| | |
Inheritance Questions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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 <tree> and use push_back to add an "elm" and an "oak" to that vector?
Last edited by venomlash; Oct 29th, 2006 at 7:26 pm.
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
Venomlash back again.
Wrote a code snippet, compiler didn't like it. The pain, the pain, the pain. Of course, it might just be that I'm not good with inheriting classes, so anyone who can get this to work, good job!:!:
Byyye!
Wrote a code snippet, compiler didn't like it. The pain, the pain, the pain. Of course, it might just be that I'm not good with inheriting classes, so anyone who can get this to work, good job!:!:
Byyye!
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
>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 <tree> 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<tree*> rather than vector<tree>. 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.
>called "elm" and "oak", can I, using all three header files, create a
>vector <tree> 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<tree*> rather than vector<tree>. 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.
I'm here to prove you wrong.
•
•
•
•
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...
Venomlash?
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
•
•
•
•
Huh? What's a pointer?
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:
"Technological progress is like an axe in the hands of a pathological criminal."
>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:
>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:
I'm here to prove you wrong.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Find word in file!!
- Next Thread: Palindrome
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






