Jump to content
  • Advertisement
Sign in to follow this  
My_Mind_Is_Going

RESOLVED Why would a derived class not be inheriting a data member? (C++)

This topic is 3986 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

This is a really strange problem, I have a class that declares some data members (protected) and I have another class that derives from it. The derived class is "getting" all of said data members except, for some reason, one of them. What could possibly cause something like this to happen? I have another class deriving from the same base class and it is getting everything fine. [Edited by - My_Mind_Is_Going on July 27, 2007 2:32:21 AM]

Share this post


Link to post
Share on other sites
Advertisement
Could you show some code? I assume everything is public/protected if another class inherited it.

Share this post


Link to post
Share on other sites
It's basically like this:



class BaseClass
{

...

protected:

MyTypeA data1 ;
MyTypeB data2 ;
MyTypeC data3 ;

}

class Derived1 : public BaseClass
{

...
// inherits data1, data2, data 3 fine

} ;

class Derived2: public BaseClass
{
...
// inherits data1, and data2 but for some reason not data3

} ;




The actual code is kind of a mess, but I can post it if this isn't enough info.



Share this post


Link to post
Share on other sites
It usually helps to see actual code, because there's often something that you won't recreate in pseudocode that's causing it.

Have you tried simplifying all of the code? What error are you getting?

Share this post


Link to post
Share on other sites
well now it's crashing every time I try to run the program, (I swear I didn't touch anything!) which may or may not be related to this problem :) I'll post the code once I get this resolved.

Edit:

This is an interesting side problem. So the base class has a method Draw which calls a virtual function OnDraw which I'm using to call the Render method in the derived class. I can call Render fine on it's own but when I let the virtual function mechanism handle it, it seems to be making everything crash. Unless I run it through the debugger then it only crashes (access violation both cases) on exiting. *sigh*

Edit2: No it just crashes period, nothing to do with particular function calls.

The thread 'Win32 Thread' (0xc18) has exited with code 0 (0x0).
HEAP[game.exe]: Invalid Address specified to RtlFreeHeap( 003F0000, 003F6400 )

[Edited by - My_Mind_Is_Going on July 27, 2007 1:39:55 AM]

Share this post


Link to post
Share on other sites
Remove things until it works, then put back the last thing and try removing something else. Continue until you have a minimal example that demonstrates your problem. Then post it.

Share this post


Link to post
Share on other sites
It looks like just having an instance of the other derived class, the one that was "working" was causing it to crash. I commented out the "data3" object in the Base class definition (so there is not longer such a data member) and now it's fine so there really is something screwy about that object. It's a bounding sphere object, nothing too complex going on in it. Maybe the file is corrupted? Will investigate...

EDIT: The BoundingSphere class has two data members: float r and float position[3]. In the default constructor I initialize position[0] = 0.0, position[1] = 0.0 and apparently the assignment: position[2] = 0.0 is what's causing the crash. What the f@ck?

Share this post


Link to post
Share on other sites
More likely it's memory corruption caused by some part of your code...

(Did you do a clean build? I don't know how your code is arranged, but it almost sounds like it's some binary incompatibility between two cpp files built with different versions of a header)

Share this post


Link to post
Share on other sites
Yeah I did a clean build. Do you think I could be writing over memory I'm not supposed to somewhere else? Earlier today I was having problem with access violations and I switched the order of some storage allocation calls and it went away (bad thing to do I'm sure).

The only unusual thing about my project structure is I have a lot of files in a "library" directory of modules I use in multiple projects (so I always modify the same copy and don't have 5 different forks of a particular class or something) and then I have the rest of my files in the current project directory.

Edit: Back to the original problem with inheritance for a second, when I use the class browser in Visual C++ and I click on one of my derived types and then click "base types" it shows me a version of my base class that is missing all the things that this class seems to be missing. It's weird because it's showing me my own code with lines missing.

Edit: Okay, I'm an idiot there were two copies of the header and my whole separation of files into two locations was keeping me from discovering it immediately.

[Edited by - My_Mind_Is_Going on July 27, 2007 2:57:44 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!