Doubt in polymorphism

Discussion in 'C++' started by Rohithzhere, Nov 5, 2008.

  1. Rohithzhere

    Rohithzhere New Member

    Joined:
    Nov 4, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    I have worked on c++ for a reasonable amount of time.

    But i am not strong in polymorphism.

    Now suppose i have

    Code:
    Class SHAPE
    {
       public:
               Print() {///Code }
    }
    
    class Triangle: public SHAPE
    {
         public :
              Print() { }
    }
    
    
    In the above example, Triangle and SHAPE are polymorphic.

    But if the case is


    Code:
    Class SHAPE
    {
       public:
               Print() {///Code }
      private:
            int a[100];
            double color;
    
    }
    
    class Triangle: public SHAPE
    {
    
         public :
              Print() { }
          private:
            int a;
    }
    
    Are these 2 classes still polymorphic


    And also if the case is


    Code:
    Class SHAPE
    {
       public:
               Print() {///Code }
      
            int a[100];
            double color;
    
    }
    
    class Triangle: public SHAPE
    {
    
         public :
              Print() { }
          
            int a;
    }
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    The misconception about polymorphism is they can only be related to functions which comes when you read books who themeselve do not know abotu polymorphism but the real meaning of polymorphism is giving poly ( many ) usage of the same thing whether it be function / class / object / even a variable.

    Say if I declare an int i and then use the same int i in loops thrice then that also means polymorphism because the variable I declared was used to loop through 3 context and I know its bad programming but then its polymorphism.

    In your case you always have the function but if the function would have been not there then also it would have been polymorphism.
     
  3. Rohithzhere

    Rohithzhere New Member

    Joined:
    Nov 4, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Oh ok, thanks dude.

    One more doubt. Is there any special case where a child class is not a polymorphic version of its base class? Is polymorphism' s basic idea up-casting and down casting?


    Thanks and Regards,
    Rohith.H.N
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Polymorphism is just giving more than one task to it and it is independent of up/down casting
     
  5. imported_xpi0t0s

    imported_xpi0t0s New Member

    Joined:
    Jul 18, 2008
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    > Is there any special case where a child
    class is not a polymorphic version of its base class? Is polymorphism' s basic idea up-casting and down casting?

    I think you could be confusing polymorphism with inheritance. Triangle is derived from SHAPE; it inherits SHAPE's functionality and data. In themselves neither Triangle nor SHAPE are polymorphic; this is about what you do with classes.

    If you had another class Square also derived from SHAPE this too isn't polymormphism, although is a necessary prerequisite to it.

    Now suppose you have a drawing program which draws triangles and squares, using a list of type SHAPE and calling SHAPE->draw(), where draw() is defined in Triangle and Square (and SHAPE, of course, where it could either be a default draw operation or virtual void draw()=0, the latter of which would also prevent you instantiating SHAPEs). THAT is polymorphism - poly=many; morph=shape/type, not to mention the Red Dwarf episode Polymorph where a creature was able to determine its own appearance) so a pointer-to-SHAPE is being used as a pointer to many different things.

    Any use of a SHAPE* pointer to manipulate a Triangle or Square object would constitute polymorphism.
     
  6. Rohithzhere

    Rohithzhere New Member

    Joined:
    Nov 4, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Thanks,Thank you very much

    Regards,
    Rohith.H.N
     
  7. hkp819

    hkp819 New Member

    Joined:
    Dec 4, 2008
    Messages:
    59
    Likes Received:
    1
    Trophy Points:
    0
    the doubt of polymorphism is only resolve by the practice, so do practice by reading books and practicing programs
    any way polymorphism is

    Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions. Poly, referring to many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts.
     
  8. preaskcli

    preaskcli New Member

    Joined:
    Dec 20, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hm ...

    To start :

    lspci | grep Network


    If you get something like this :


    03:00.0 Network controller: Broadcom Corporation BCM4322 802.11a/b/g (rev 02)

    You need to use ndiswrapper for install drivers.

    But 1st,as we know this is Debian platform now and i think that u can try this :

    sudo apt-get install b43-fwcutter

    If you get some message after install just click ok.
     
  9. gsuryaprasath

    gsuryaprasath New Member

    Joined:
    Jul 12, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Polymorphism :

    Polymorphisms is a generic term that means 'many shapes'. More precisely Polymorphisms means the ability to request that the same operations be performed by a wide range of different types of things.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice