J
jungleman
I have some problems in the following examples:
// where code begins
class base
{
public:
virtual bool operator == (const base& b) const = 0;
}
class inheritanceA
{
public:
virtual bool operator == (const inheritanceA& b) const
{cout << "operator == in inheritanceA"}
}
class inheritanceB
{
public:
virtual bool operator == (const inheritanceB& b) const
{cout << "operator == in inheritanceB"}
}
int main()
{
base* a = new inheritanceA;
base* b = new inheritanceB;
cout << (*a)==(*b) << endl;
return 0;
}
problems coming:
but the codes above is wrong while compiling, if I change the method
function in class inheritanceA, virtual bool operator==(const base&
b), It will be Ok.
however, when I add a data base* c = new inheritanceB, and invokes
operator == like this: (*a)==(*c), It will invokes method operator ==
in class inheritanceA,
but what I want is the compiler says it to be wrong .
How can I do this in polymorphism?
thanks
// where code begins
class base
{
public:
virtual bool operator == (const base& b) const = 0;
}
class inheritanceA
{
public:
virtual bool operator == (const inheritanceA& b) const
{cout << "operator == in inheritanceA"}
}
class inheritanceB
{
public:
virtual bool operator == (const inheritanceB& b) const
{cout << "operator == in inheritanceB"}
}
int main()
{
base* a = new inheritanceA;
base* b = new inheritanceB;
cout << (*a)==(*b) << endl;
return 0;
}
problems coming:
but the codes above is wrong while compiling, if I change the method
function in class inheritanceA, virtual bool operator==(const base&
b), It will be Ok.
however, when I add a data base* c = new inheritanceB, and invokes
operator == like this: (*a)==(*c), It will invokes method operator ==
in class inheritanceA,
but what I want is the compiler says it to be wrong .
How can I do this in polymorphism?
thanks