求助:继续向各位大哥请教几个类的问题,谢谢!
//m.h
#ifndef _M_H
#define _M_H
#include "a.h "
#include "b.h "
class M
{
public:
A aa;
B bb;
int m;
};
#endif
//a.h
#ifndef _A_H
#define _A_H
class A
{
public:
int f1(){ return 0;};
void f2(){};
};
#endif
//b.h
#ifndef _B_H
#define _B_H
class M;
class A;
class B
{
public:
B();
B(const B&);
~B();
B& operator=(const B&);
int f1();
int get_m()const;
void f2();
private:
A *pa;
M *pm;
};
#endif
//b.ccp
#include "b.h "
#include "a.h "
#include "m.h "
B::B():pm(new M),pa(new A)
{
//...
}
B::B(const B& cb):pm(new M),pa(new A)
{
pm-> m=cb.get_m();
//...
}
B& operator=(const B& cb)
{
if(&cb=this)
return;
//...
}
B::~B()
{
delete pm;
delete pa;
}
int B::f1()
{
pm-> m = pa-> f1();
return pm-> m;
}
int B::get_m()const
{
return pm-> m;
}
请教:
1:
为什么 类 M 上面不要
class A;
class B;
啊
2:
类 M 中的A ,B 怎么写构造函数和析构函数
谢谢!
[解决办法]
你不知道MM的名字能和MM处吗?
[解决办法]
不明白的话,可以加我QQ,171828563