|
-
January 17th, 2003, 09:14 PM
#1
Polymorphic not?
I have the following piece of code:
Code:
CLocation* CLocation::CreateNewLocation( ... ) // Static Function
{
// May return pointers to different classes derived from
// CLocation, but for this example:
return new CShapeLocation();
}
...
// Main Code
CLocation* pLocation = CLocation::CreateNewLocation( ... );
pLocation->DoPropertiesDlg() ;
But...
CLocation:: DoPropertiesDlg()
is ALWAYS called, not..
CShapeLocation:: DoPropertiesDlg()
as I would have expected. What am I doing wrong?
Thanks
Rob.
-
January 17th, 2003, 09:19 PM
#2
You neglected to produce the most important piece of code: the
declaration of the DoPropertiesDlg() function. Is it possible that
you forgot to declare the DoPropertiesDlg() function virtual? If
you did not, you'd better make the destructor virtual as well.
--Paul
-
January 17th, 2003, 09:24 PM
#3
Yes, it is declared virtual:
Code:
virtual bool DoPropertiesDlg( ... ) { ASSERT(false); return false; };
-
January 17th, 2003, 09:59 PM
#4
I found what my problem was.
The derived function was not declared EXACTLY the same as the base one. One of the parameters in the base function was a CLocation*. In the derived I had declared it as CShapeLocation*. My mistake.
Thanks
Rob.
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
|