Include Problem

Hello,
I try to program C++, but I get some errors. Can you please help me.

Error:
1
2
3
4
5
6
Fehler	3	error C2061: Syntaxfehler: Bezeichner 'Test2' 
\test\test1.h	9	1	Test
Fehler	1	error C2061: Syntaxfehler: Bezeichner 'Test1'
\test\test2.h	9	1	Test
Fehler	2	error C2061: Syntaxfehler: Bezeichner 'Test1'	
\test\test2.h	9	1	Test


Main.cpp
1
2
3
4
5
6
7
#include "Test1.h"
#include "Test2.h"

int main(){
	Test1 t1();
	Test2 t2();
}


Test1.h
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once
#include "Test2.h"

class Test1
{
public:
	Test1();
	~Test1();
	void blu(Test2 t);
};



Test2.h
1
2
3
4
5
6
7
8
9
10
#pragma once
#include "Test1.h"

class Test2
{
public:
	Test2();
	~Test2();
	void blu(Test1 t);
};


thank you
Do you have corresponding Test1.cpp and Test2.cpp? In other words, have you actually implemented your constructors, destructors and methods?
yes.
Test1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Test1.h"


Test1::Test1()
{
}


Test1::~Test1()
{
}

void Test1::blu(Test2 t){

}


Test2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Test2.h"


Test2::Test2()
{
}


Test2::~Test2()
{
}

void Test2::blu(Test1 t){

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Test1.h"


Test1::Test1()
{
}


Test1::~Test1()
{
}

void Test1::blu(Test2 t){

}


Your blu() method takes a Test2 object, but this file knows nothing about Test2. Try including test2.h as well as test1.h
I include Test2.h in Test1.h and Test1.h in Test1.cpp. Is this wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Test1.h"
#include "Test2.h"

Test1::Test1()
{
}


Test1::~Test1()
{
}

void Test1::blu(Test2 t){

}

Doesn't work, too.
You need to look into forward declarations of test 2 so that the program will know about test 2 and can therefore compile the blu function, without you having to declare all of test 2, which includes a function taking a test 1. For more information, just google c++ forward declarations.
Test1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once
#include "Test2.h"

class Test2;

class Test1
{
public:
	Test1();
	~Test1();
	void blu(Test2 t);
};


Test.h
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once
#include "Test1.h"

class Test1;

class Test2
{
public:
	Test2();
	~Test2();
	void blu(Test1 t);
};


It works ,
thank you.
Topic archived. No new replies allowed.