Archived

This topic is now archived and is closed to further replies.

functions and inheritence

This topic is 5574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how come I cant do this
    
class foo
{
};
class fubar : public foo
{
};
foo *fn(void)
{
fubar *fu = new fubar;
return fu;
}

void main()
{
fubar *fu = fn();
}
    
the compiler complains because the "types are unrelated" [edited by - evilchicken on September 9, 2002 6:34:42 PM] [edited by - evilchicken on September 9, 2002 6:45:09 PM]

Share this post


Link to post
Share on other sites
You should have a virtual destructor defined for foo.

EDIT:
Also, you should NOT have a semicolon after:
class fubar : public foo


--------------------
Matthew Calabrese
Realtime 3D Orchestra:
Programmer, Composer,
and 3D Artist/Animator
"I can see the music..."

[edited by - Matt Calabrese on September 9, 2002 6:37:17 PM]

Share this post


Link to post
Share on other sites
oh nevermind, in your int main() if you change foo to fubar (which is what I want) how come it doesnt work?

I can assign fubar to foo, but not foo to fubar.

right now I managed to work around the problem by making function return a void pointer and recasting it to the proper subclass. is there a less hackish way of doing this?

[edited by - evilchicken on September 9, 2002 7:50:55 PM]

Share this post


Link to post
Share on other sites