我有两个A类,B类。
对于 A,我有两个方法 callB()
和 checksomethinginB()
。
对于 B,我有一个方法 execute()
。
我像这样使用它们:
A _a;
_a.callB(); //inside the function, B object _b will be created
//after _b created, in another place, _b will execute _b.execute().
_b.execute()
{
// I want to use A method checksomethinginB()
}
所以我不知道在 B 中使用 A 方法的好方法,我可以创建的是使用静态函数,但我认为也许有更好的方法,感谢您的建议!!
最佳答案
将 A
的正确实例传递给 B
的构造函数,或者在需要时传递它。
如果 checksomethinginB
不需要 A
中的任何状态,那么它当然可以是静态的。
关于c++ - C++中嵌套函数的设计模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13321855/