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?
Printable View
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?
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.
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..
You didn't explain virtual funcitons...
Anyways, here. I have the thread ID memorized by now :p
29792
how special
Yeah, I thought that was kind of odd too, heh