-
erased pointer
I have a problem in some code I've been writing lately.
Suppose I have the following code:
Code:
class A{
public:
Vector3D* point;
};
class B{
public:
A* obj;
float computeSomething( Vector3D* point );
};
float B::computeSomething( Vector3D* point ){
Vector3D* v = someObject->getVector();
float result = *point * *v;
return result;
}
Then at some point inside a function of class B I do:
Code:
float m = computeSomething( obj->point );
My problem is, pointer obj is correctly initialized before the call to function computeSomething, meaning that it points to an instance of class A, but after the function call the pointer is NULL!
It seems that somhow the instance of class A gets erased.
Does someone know why?
Ed.
-
can you show us the overloaded multiplication operator for Vector3D?
generally you should pass the vector3d per const reference or const pointer at least. then the compiler will lead you to the problem.
Code:
float B::computeSomething( const Vector3D & point )
{...}
or
Code:
float B::computeSomething( const Vector3D * const point )
{...}
-
Thank you, I resolved the problem. It was in fact related to passing a non const pointer.