// 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
// b.h
#pragma once
#ifndef _B_H_
#define _B_H_
#include "a.h"
#include <iostream>
usingnamespace 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;
}
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 ==========