How to acces previosly created classes from a sub class?

Pages: 12
@ravel: From Gearbox.h you must include Car.h.
Anyways, if you want to add components to a car, you should follow your older route, so, ignore what I wrote above.
Just make sure to declare bodies in .cpp and functions/variables in .h.
 
Unhandled exception at 0x64d422a6 (MoDyEnPhysics.dll) in Unity.exe: 0xC0000005: Access violation reading location 0xcdcdce61.


it breaks at engine class, seems like the class is not defined

1
2
3
4
5
6
7
8
-		this	0xcdcdcdcd {torqueCurve={...} compressionCurve={...} inertia=??? ...}	CarEngine * const
+		torqueCurve	{p=??? valuesLen=??? values=0xcdcdcdd5 [...]() }	Curve
+		compressionCurve	{p=??? valuesLen=??? values=0xcdcdce05 [...]() }	Curve
		inertia	CXX0030: Error: expression cannot be evaluated	
		throttle	CXX0030: Error: expression cannot be evaluated	
		idleThrottle	CXX0030: Error: expression cannot be evaluated	
		idleRPM	CXX0030: Error: expression cannot be evaluated	
		stallRPM	CXX0030: Error: expression cannot be evaluated	
Last edited on
> As for the code, its huge and I'm not going to post the whole code.
Then try to reproduce your problem in an smaller program. It should be obvious that you need to paste the errors that correspond to the smaller testcase
http://www.eelis.net/iso-c++/testcase.xhtml (6)

> Tryed the other mehtod aswell, and I got that the base class is undefined...
> error C2504: 'CarClass' : base class undefined
http://www.cplusplus.com/forum/general/113904/


> Now I got a new issue, the dll I compiled crashed while trying to run it.
probably your `car' pointer is invalid. Hard to say without seeing the code for the constructors and how it is invoked.
http://www.cplusplus.com/forum/general/112111/
Last edited on
this 0xcdcdcdcd


Yup, that's a bad (uninitialized) pointer.

You must be trying to access a pointer without first assigning it so that it actually points to an object.
uhm, any possible solutions?
Last edited on
Your engine class is defined and accessible. This is not a compilation problem.

It's a logic problem. You are creating a pointer, then trying to get the data it points to -- but you never tell it to point to anything.

Example:

1
2
3
4
5
6
7
std::string* foo;  // a pointer to a string

// but note that we never actually assign it, so it is a bad/uninitialized pointer.

cout << foo->length(); // <- prints the length of whatever string we are pointing to
// But again!  What string?  We never say!  We have a pointer that points to nothing
//  so how can the computer know the length of a string which doesn't exist? 



So you have a pointer in your code somewhere. And you are accessing the object it points to. But you never actually made it point to anything. That's why this is crashing.

You probably forgot to do this part:

I wrote:
The MyClass object will then need to tell the SubClass who the owner is (ie: it will need to provide that pointer. You can probably do this in the MyClass constructor:


1
2
3
4
 MyClass::MyClass()
{
    mySubClass.owner = this;  // tell the sub class that 'this' is the owner
}

Oh silly me, I had it commented out... Now it works,
Thank you veryvery much for explaining me this and helping me out!
Topic archived. No new replies allowed.
Pages: 12