Why don't you write a simple code snippet and see? If the compiler doesn't complain, then it should be allowed.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Try making a vector of Tree*, and add elements which are Oak* and Elm*. Of course, this means you'll be working with pointers, but I'm assuming that you'll be fine with that...
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
>If I create a class called "tree" and inherit from it to classes
>called "elm" and "oak", can I, using all three header files, create a
>vector and use push_back to add an "elm" and an "oak" to that vector?
Polymorphism only works through references, so you'll want a vector rather than vector. But if that's the case, yes you can do what you want. However, you'll end up with a heterogenous data structure, and you need a way to figure out which tree is which if you plan on using anything but inherited members.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
I'm glad you have a sense of humor? I'm sorry your first post didn't leave me with a clear impression of how familiar you are with C++? Do you need anything else? Maybe a few question marks?
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
Huh? What's a pointer?
Do you think this will help? http://www.cprogramming.com/tutorial/lesson6.html
I'm sorry if everyone is starting to be sarcastic with these question marks we don't mean anything, hopefully it doesn't offend you?
I mean... :cheesy:
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>I'm sorry if everyone is starting to be sarcastic with these question
>marks we don't mean anything, hopefully it doesn't offend you?
Yes, please don't take offense? Friendly banter is one of the best things about this forum? But our humor can be a little weird sometimes? Eh? Eh? Yes? No? :cheesy:
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401