|
-
February 2nd, 2009, 11:47 PM
#1
Can a base class pointer call methods in the derived class?
I have a base class pointer which is assigned a derived class. Can this pointer call methods in the derived class which are not declared in the base class?
i.e.
class BaseClass
{
........
};
class DerivedClass : public BaseClass
{
void Print(); //declared in DerivedClass only
.......
};
BaseClass* ReturnClassType()
{
//some method logic here
.............
DerivedClass* dc;
return dc;
}
BaseClass* bc = ReturnClassType();
bc->Print();
When I called print() using the base class pointer, there is a compile error saying that the method is not found in the base class.
Is it possible for base class pointers to call methods declared in the derived class only?
Last edited by ZhiYi; February 3rd, 2009 at 12:49 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|