更新:ファイルを明確にして、質問を繰り返しましょう:
main.h
#include "other.h"
class MyClass
{
public:
void MyMethod();
void AnotherMethod();
OtherClass test;
}
main.cpp
#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のメソッドを呼び出します。このようなことは可能だと確信していますが、設計が悪いだけかもしれません私の分。どんな方向性でも大歓迎です。