A
axel22
Hello,
I have the following problem. I create a class called MyClass which
includes another class calles MyContainer. Class MyContainer has a
member which is a vector, instantiated as vector<MyClass>. When trying
to compile this I receive an error. Here is how it goes:
---------------
MyClass.h
---------------
#pragma once
#include "MyContainer.h"
class MyClass {
private:
int myInteger;
public:
MyClass(void);
~MyClass(void);
};
The reason why MyContainer.h is included here is because I would later
like to make
it a private member of MyClass.
---------------------
MyContainer.h
---------------------
#pragma once
#include "MyClass.h"
#include <vector>
using namespace std;
class MyContainer {
private:
vector<MyClass *> myVector;
MyClass *pointer;
public:
MyContainer(void);
~MyContainer(void);
};
-------------
main.cpp
-------------
#include <iostream>
#include "MyClass.h"
#include "MyContainer.h"
void main() {
MyClass myInstance;
MyContainer myContainerInstance;
}
Output goes like this:
------ Build started: Project: Probarka, Configuration: Debug Win32
------
Compiling...
main.cpp
f:\C++\Projects\Probarka\MyContainer.h(10) : error C2065: 'MyClass' :
undeclared identifier
f:\C++\Projects\Probarka\MyContainer.h(10) : error C2059: syntax error
: '>'
f:\C++\Projects\Probarka\MyContainer.h(15) : error C2143: syntax error
: missing ';' before '}'
f:\C++\Projects\Probarka\MyClass.h(5) : error C2143: syntax error :
etc. etc.
To sum it up: why can't I create a class which has a template member
instantiated with another class which includes the first class? How can
I solve this problem?
I have the following problem. I create a class called MyClass which
includes another class calles MyContainer. Class MyContainer has a
member which is a vector, instantiated as vector<MyClass>. When trying
to compile this I receive an error. Here is how it goes:
---------------
MyClass.h
---------------
#pragma once
#include "MyContainer.h"
class MyClass {
private:
int myInteger;
public:
MyClass(void);
~MyClass(void);
};
The reason why MyContainer.h is included here is because I would later
like to make
it a private member of MyClass.
---------------------
MyContainer.h
---------------------
#pragma once
#include "MyClass.h"
#include <vector>
using namespace std;
class MyContainer {
private:
vector<MyClass *> myVector;
MyClass *pointer;
public:
MyContainer(void);
~MyContainer(void);
};
-------------
main.cpp
-------------
#include <iostream>
#include "MyClass.h"
#include "MyContainer.h"
void main() {
MyClass myInstance;
MyContainer myContainerInstance;
}
Output goes like this:
------ Build started: Project: Probarka, Configuration: Debug Win32
------
Compiling...
main.cpp
f:\C++\Projects\Probarka\MyContainer.h(10) : error C2065: 'MyClass' :
undeclared identifier
f:\C++\Projects\Probarka\MyContainer.h(10) : error C2059: syntax error
: '>'
f:\C++\Projects\Probarka\MyContainer.h(15) : error C2143: syntax error
: missing ';' before '}'
f:\C++\Projects\Probarka\MyClass.h(5) : error C2143: syntax error :
etc. etc.
To sum it up: why can't I create a class which has a template member
instantiated with another class which includes the first class? How can
I solve this problem?