Polymorphism and class operators

This is a discussion on Polymorphism and class operators within the C++ Programming forums, part of the General Programming Boards category; can anyone explain to me what polymorphism is? The book's definition is overexceedingly confusing. Can anyone explain to me how ...

  1. #1
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859

    Polymorphism and class operators

    can anyone explain to me what polymorphism is? The book's definition is overexceedingly confusing.

    Can anyone explain to me how to use operators in a class?
    Last edited by Yoshi; 01-20-2003 at 02:10 PM.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Polymorphic OOP is the guy you want to talk to, if he's online
    adress him, im sure he'll be glad to explain it.

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Ok.. now you consider a situation where the function name and prototype is the same in both the base and derived classes.. For example, consider the following


    Code:
    class cpro{
    
    int x;
    public show(){cout<<x;};
    }
    
    
    class vasanth:public cpro
    {
    int y;
    public:
    show(){cout<<y;};
    
    }

    now how the hell can you use the member function show() to print the values of objects of both the classes. Since the prototype of show() is the same in both the places.. The function is not overloaded(i.e same name but different prototype) and therefore static binding does not apply here.. So in this cases we can use the class resolution operator to specify the class while invoking the function with the derived class objecs..


    But it will be advantageous if we could select the function at runtime... his is known as runtime polthis is done by a mechanism supported by c++ known as virtual functions.... SO this is what polymorphism is all about.. differenciating between the methods of two classes having the same name and prototype....



    and i dont undersand what you mean by operator .. but i asume that you are talking about operator overloading..

    below is an example of overloaded +


    Code:
    class complex{
    
    int real,imag;
    
    
    public:
             blah()
             blahblah blah...
       
            complex operator+(complex);
             
           
    
    
    }
    
    
    complex      complex::operator+(complex temp)
    {
    
    complex c1;
    temp.real=temp.real+real;
    temp.imag=temp.imag+imag;
    
    
    return temp;
    
    
    
    }

    sothe operators can be used advbantageously to add dates, feet,inches etc... actually they are used in a wider and even specialised area... i had overloaded operator + to merge two files..
    Last edited by vasanth; 01-20-2003 at 11:37 AM.

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    You didn't explain virtual funcitons...

    Anyways, here. I have the thread ID memorized by now

  5. #5
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    29792

    how special
    Yoshi

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yeah, I thought that was kind of odd too, heh

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 01-13-2008, 05:57 PM
  2. Linked List Class with Pointers to Objects and using Polymorphism
    By CaptainMorgan in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2006, 11:41 AM
  3. polymorphism problem
    By mrafcho001 in forum C++ Programming
    Replies: 5
    Last Post: 03-12-2006, 12:03 AM
  4. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  5. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 09:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21