|
-
July 16th, 2012, 02:57 AM
#1
Subclass objects in one array?
Hi
i want to save similar objects, meaning having same superclass, in an array. Example: I have a superclass vehicle. Class car and truck inherit from vehicle. Now i have a few from both of them an want to put them in an array, vector, set or else. Is this possible in C++ or are there an workarounds? When i remember right, Java and C# offer this feature.
Here again an example:
Code:
class vehicle{
int mMaxSpeed;
}
class truck : public vehicle{
int mTrailerLength;
}
class car : public vehicle{
bool mHasHitch;
}
main()
{
truck mytruck = new truck();
car mycar = new car();
vector<vehicle> myCarPool;
myCarPool.pushback(mytruck);
myCarPool.pushback(mycar);
}
Greets
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
|