class B;
class C
{
public:
void print()
{
std::cout << "this is c" << std::endl;
}
};
class A
{
public:
A(B*b)
{
b_ptr = b;
}
void print()
{
std::cout << "this is b" << std::endl;
}
public:
B* b_ptr;
};
class B
{
public:
B()
{
CreatePtr();
}
void print()
{
std::cout << "this is a" << std::endl;
}
void CreatePtr()
{
c_ptr = new C;
}
public:
C* c_ptr;
};
void main()
{
B *b = new B;
A *a = new A(b);
b->print();
b->c_ptr->print();
a->print();
a->b_ptr->c_ptr->print();
}
請問標紅這種多層呼叫方式合理嗎,總感覺不太舒服
uj5u.com熱心網友回復:
語法上允許啊,至于舒不舒服,是你的設計問題。uj5u.com熱心網友回復:
關鍵是你想達到一個什么效果?也就是你的需求是什么?uj5u.com熱心網友回復:
換個4k大螢屏看就舒服了
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/49193.html
標籤:C++ 語言
上一篇:Victor 串口控制元件包中的例子作為子表單添加到父表單時報錯
下一篇:這兩個題怎么解鴨
