compile error?

Hi,
When I run the following code.it gives the error
Where is the wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// a.h
#pragma once
#ifndef _A_H_
#define _A_H_
#include "b.h"


class B;

class A {
public:
	B *b;
	int i;
	A(int ii)
	{
		b = new B(56);
		i = ii;
		cout << "I AM a`S CONSTURCTOR" << endl;
	}

	void display1()const
	{
		cout << i << endl;
		b->display2();
		cout <<"cikti aldim CLASS A"<< endl;
	}

};




#endif


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// b.h

#pragma once
#ifndef _B_H_
#define _B_H_



#include "a.h"
#include <iostream>

using namespace std;

class A;

class B{
public:
	A *a;
	int i;

	B(int ii)
	{
		i = ii;
		a = new A(45);
		cout << "I AM b`S CONSTURCTOR" << endl;
	}

	void display2()const
	{
		cout << i << endl;
		a->display1();
		cout <<"cikti aldim CLASS B"<< endl;
	}

};

#endif


1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{

	B b(23);
	A a(54);


	b.display2();
	
	return 0;		
}


You forgot to post the error message.
You can't call B constructor before it was declared ( line 16 of a.h )
This is the reason source file exist ;^)
@Athar
error;


1> main.cpp
1>c:\users\firix\desktop\new proje\x\x\b.h(22): error C2514: 'A' : class has no constructors
1> c:\users\firix\desktop\new proje\x\x\b.h(12) : see declaration of 'A'
1>c:\users\firix\desktop\new proje\x\x\b.h(29): error C2027: use of undefined type 'A'
1> c:\users\firix\desktop\new proje\x\x\b.h(12) : see declaration of 'A'
1>c:\users\firix\desktop\new proje\x\x\b.h(29): error C2227: left of '->display1' must point to class/struct/union/generic type
1>main.cpp(1554): warning C4520: 'rand3' : multiple default constructors specified
1>main.cpp(1620): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(3187): warning C4244: '+=' : conversion from 'long double' to 'int', possible loss of data
1>main.cpp(3191): warning C4244: '+=' : conversion from 'long double' to 'int', possible loss of data
1>main.cpp(3234): warning C4244: '+=' : conversion from 'long double' to 'int', possible loss of data
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.28
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Last edited on
@Bazzy

I do not understand what was wrong
Topic archived. No new replies allowed.