Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

how does a child keep track of a parent?

I'm getting an compile error that does not quite make sense.

I have the following two classes. StressFile object has a vector of LoadCase objects. StressFile is the parent and the children are the different loadCases in the loads vector.

class LoadCase
{
double x,y,z;
LoadCase(vector<string> & data);
}

class StressFile
{
double Area;
vector<LoadCase> loads;
StressFile(string & file);
}

The stress file constructor:

StressFile::StressFile(string & file)
{
vector<string> lines;
while(notDone)
{
//
// some logic here to keep track of the lines of data that belong to each case
//
loads.pushBack(LoadCase(lines));
}
}

So, as shown, the code compiles and works without problems.

However, I now have a loadCase memeber function that requires the use of Area variable in StressFile.

double LoadCase::doSomeMathHere();
{
return x/z + y*area;
}

so I thought I should just pass the address of the StressFile ojbect as a parameter when I create a LoadCase ojbect.

class LoadCase
{
double x,y,z;
LoadCase(vector<string> & data, StressFile * belongsTo);
}

also in LoadCase.cpp file, I added #include "StressFile.h".
StressFile.cpp already had #include "LoadCase.h"

However by just adding this extra parameter, I get the following error.

Compiling...
LoadCase.cpp
c:\Documents and Settings\user\Desktop\Sea\stressfilereader\LoadCase.h(13) : error C2226: syntax error : unexpected type 'std::vector<_Ty>'
with
[
_Ty=std::string
]



-------------------
After some searching...I found this.
http://www.dev-archive.com/tips/Tip/12583

so by using foward declaration, it worked.

Thanks!
[2013 byte] By [rssmps] at [2007-11-11 8:37:56]