Hey,
Anyone mind pointing out what I'm doing wrong?
I've got objects of two different classes in main(). The two classes both work with these two objects, so both require the reference to eachothers objects. e.g. class1 requires class2's object on construction, and visa versa.
Code:
int main()
{
CVector* Vectors;
CPlane* Water;
Vectors = new CVector(Water);
Water = new CPlane(Vectors);
}
/*
They will both be linked lists eventually. CVector is simply x, y, z
points, in a linked list fashion. CPlane is a 2d plane which uses
CVector to plot the points, but also has a function which can be
used to 'reflect properties' (like a mirror) of the vectors in front of
it (since this is Water (on no angle, facing up), it reflects vectors
at the y axis).
*/
My problem is that the constructor is requiring I initialize the variable holding the object information, or else it returns an error: 25 C:\Programming\Projects\Game\v0003\Vector.h uninitialized reference member `CVector::m_Registrar'. The below code is what I'm forced to do.
Code:
class CVector {
private:
CPlane*& m_Registrar;
public:
CVector(CPlane*& p_Registrar) : m_Registrar(p_Registrar) {}
};
I would prefer not having to do that since there are some cases I wouldnt want to keep passing an object to m_Registrar, when I don't plan on using the m_Registrar variable. Anyone know the way around this?
I've also got a part of code that sends the points its searching for in the linked list to the vector object, using Search(), then when it finds the object match, it returns the object, which is the object I want m_Vectors to become.
m_Vectors->Search() returns a CVector
Code:
CVector CVector::Search(long p_id) {}
...
CVector*& m_Vectors;
m_Vectors = m_Vectors->Search();
returns error:
145 C:\Programming\Projects\Game\v0003\Vector.cpp cannot convert ` CVector' to `CVector*' in assignment
Is overloading the operator= and doing all the converting manually the only way? or cant I return a pointer to the CVector object, and set m_Vector to that, since is its a reference to a pointer. I forget.. now I'm just trying to please the compiler, then I'll go back and fix it after
I might just stop and read, I've obviously lost all concept of C++ pointers and references, and some rules.
Dae