64,746
社区成员
发帖
与我相关
我的任务
分享
class B;
calss A{
B* m_pb;
pbulic:
A(const B *pb):m_pb(pb){};
};
class B{
....
};
int main()
{
B b;
A a(&b);
return 0;
}
[/quote]
大话设计模式 中的,买这书白瞎了
[/quote]
你这例子是java 吧,java 对象,似乎就是引用。引用表示关联
和上面那个指针,效果相同。
例如:
class B;
calss A{
B& m_ref;
pbulic:
A(const B &r):m_ref(r){};
};
class B{
....
};
int main()
{
B b;
A a(b);
return 0;
}
为了代码更清晰,放在代码框里