M
meyousikmann
Given these two (incomplete but representative) classes in two seperate
header files:
Class1.h
class Class1
{
public:
Class(const char CharValue, const int IntValue1, const int IntValue2);
~City();
private:
};
Class2.h
#include "Class1.h"
class Class2
{
public:
Class2(const int IntValue1, string StringValue);
~Class2();
private:
Class1 Class;
};
and an implementation file for Class2:
Class2.cpp
Class2::Class2(const int IntValue1, string StringValue)
{
Class('A', 30, 30); // trying to create an object of type Class1 within
the constructor of Class2
}
notice the data member 'Class1 Class' in Class2. What I am trying to
accomplish is to have a data member in Class2 that is of type Class1 and
create that object of type Class1 within the constructor of Class2. The
code in this form won't compile and I am not sure what to do now. I am new
to C++ and I can't seem to get this to work. Anyone help me?
header files:
Class1.h
class Class1
{
public:
Class(const char CharValue, const int IntValue1, const int IntValue2);
~City();
private:
};
Class2.h
#include "Class1.h"
class Class2
{
public:
Class2(const int IntValue1, string StringValue);
~Class2();
private:
Class1 Class;
};
and an implementation file for Class2:
Class2.cpp
Class2::Class2(const int IntValue1, string StringValue)
{
Class('A', 30, 30); // trying to create an object of type Class1 within
the constructor of Class2
}
notice the data member 'Class1 Class' in Class2. What I am trying to
accomplish is to have a data member in Class2 that is of type Class1 and
create that object of type Class1 within the constructor of Class2. The
code in this form won't compile and I am not sure what to do now. I am new
to C++ and I can't seem to get this to work. Anyone help me?