A
axel22
Hello.
The idea is to create a class MyClass which holds a container
MyContainer with pointers to other instances of MyClass:
---------------
MyClass.h
---------------
#pragma once
#include "MyContainer.h"
class MyClass {
private:
int myInteger;
MyContainer memberContainer;
public:
MyClass(void);
~MyClass(void);
};
---------------------
MyContainer.h
---------------------
#pragma once
#include "MyClass.h"
#include <vector>
using namespace std;
class MyClass; // forward declaration
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;
}
This code results in the following error output:
------ Build started: Project: Probarka, Configuration: Debug Win32
------
Compiling...
MyContainer.cpp
f:\C++\Projects\Probarka\MyClass.h(9) : error C2146: syntax error :
missing ';' before identifier 'memberContainer'
f:\C++\Projects\Probarka\MyClass.h(9) : error C2501:
'MyClass::MyContainer' : missing storage-class or type specifiers
f:\C++\Projects\Probarka\MyClass.h(9) : error C2501:
'MyClass::memberContainer' : missing storage-class or type specifiers
Generating Code...
Compiling...
MyClass.cpp
Generating Code...
Compiling...
main.cpp
Generating Code...
Build log was saved at
"file://f:\C++\Projects\Probarka\Debug\BuildLog.htm"
Probarka - 3 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
If anyone could help, I would be grateful.
The idea is to create a class MyClass which holds a container
MyContainer with pointers to other instances of MyClass:
---------------
MyClass.h
---------------
#pragma once
#include "MyContainer.h"
class MyClass {
private:
int myInteger;
MyContainer memberContainer;
public:
MyClass(void);
~MyClass(void);
};
---------------------
MyContainer.h
---------------------
#pragma once
#include "MyClass.h"
#include <vector>
using namespace std;
class MyClass; // forward declaration
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;
}
This code results in the following error output:
------ Build started: Project: Probarka, Configuration: Debug Win32
------
Compiling...
MyContainer.cpp
f:\C++\Projects\Probarka\MyClass.h(9) : error C2146: syntax error :
missing ';' before identifier 'memberContainer'
f:\C++\Projects\Probarka\MyClass.h(9) : error C2501:
'MyClass::MyContainer' : missing storage-class or type specifiers
f:\C++\Projects\Probarka\MyClass.h(9) : error C2501:
'MyClass::memberContainer' : missing storage-class or type specifiers
Generating Code...
Compiling...
MyClass.cpp
Generating Code...
Compiling...
main.cpp
Generating Code...
Build log was saved at
"file://f:\C++\Projects\Probarka\Debug\BuildLog.htm"
Probarka - 3 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
If anyone could help, I would be grateful.