更新:让我澄清我的文件并重申我的问题:
主文件
#include "other.h"
class MyClass
{
public:
void MyMethod();
void AnotherMethod();
OtherClass test;
}
主文件
#include "main.h"
void MyClass::MyMethod()
{
OtherClass otherTemp; // <--- instantitate OtherClass object
otherTemp.OtherMethod(); // <--- in this method here, is where I want to also call MyClass::AnotherMethod()
}
void MyClass::AnotherMethod()
{
// Some code
}
其他.h
class OtherClass
{
public:
void OtherMethod();
}
其他.cpp
#include "other.h"
void OtherClass::OtherMethod()
{
// !!!! This is where I want to access MyClass::AnotherMethod(). How do I do it?
// I can't just instantiate another MyClass object can I? Because if you look above in
// main.cpp, this method (OtherClass::OtherMethod()) was called from within
// MyClass::MyMethod() already.
}
所以基本上我想要的是:你实例化对象 A,然后实例化对象 B,而对象 B 又调用来自对象 A 的方法。我确信这样的事情是可能的,但它可能只是糟糕的设计我这边。任何方向将不胜感激。