|
-
Feb 1st, 2003, 03:01 PM
#1
Thread Starter
Junior Member
Class and Inheritance problem
I have a base class with about 5 classes that inherit the one base class. I also have an array of about 1000 base classes that store the class when I create it.
Baseclass BaseClasses[1024];
When I want to store the variable and use it I do this:
BaseClasses[m_iLoc] = storevariable;
Baseclass *pVar = &BaseEnts[m_iLoc];
ClassCar *pVar2 = (ClassCar *)pVar2;
pVar2->Go();
Yet when I try to get some data from the BaseClasses it seems that some of the data is wrong or corrupt. I think this is because the BaseClasses variable is Baseclass only and not one of the other classes. What can I do to fix this?
-
Feb 3rd, 2003, 10:16 PM
#2
Junior Member
Your pVar2 is not initialised to anything. You should have
ClassCar* pVar2 = (ClassCar*)pVar;
pVar2->Go();
Thats if I'm understanding what you are actually after
Last edited by gommo; Feb 4th, 2003 at 04:32 PM.
-
Feb 4th, 2003, 04:15 AM
#3
Fanatic Member
Your pVar2 is not initialised to anything. You should have
ClassCar* pVar2 = (ClassCar*)pVar1;
pVar2->Go();
What's pVar1? Shouldn't it just be pVar?
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Feb 8th, 2003, 06:35 PM
#4
Your objects are of the base class type. You may not cast them to derived class types.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|