Hehe 질문 제목 선택에 어려움을 겪고 있습니다. 그러나 문제를 명확하게 설명하기 위해 문제에 대해 설명하겠습니다.클래스 함수에 의해 제어 될 클래스 인스턴스 등록
저는 이제 DirectX 래퍼가있는 C++ 게임을위한 자체 GUI 라이브러리를 작성하고 있습니다. 그러나 "manager"클래스의 draw 함수를 호출하여 게임 내 윈도우를 렌더링하는 방법에 대해서는 전혀 알지 못합니다.
예를 들어, 이미 "관리자"및 "창"클래스가 있다고 가정 해보십시오.
관리자 :
class MyGUIManager { private: std::vector<MyGUIWindow> WindowCollector; public: MyGUIManager() { } virtual MyGUIWindow *NewWindow(char *szWindowTitle) { MyGUIWindow *temp = new MyGUIWindow(); temp->SetWindowTitle(szWindowTitle); return temp; } void RegisterWindow(MyGUIWindow targetWindow) // hopely this { this->WindowCollector.push_back(targetWindow); } void Draw() { // I wanted this function to be able to call all MyGUIWindow instances' Draw() function // can it be helped like this? for(int i = 0; i < this->WindowCollector.size(); i++) this->WindowCollector.at(i)->Draw(); // but the vector members must be referenced to each window instance.. } };
창 :
class MyGUIWindow { public: MyGUIWindow() { this->SetWindowTitle("New Window"); } void SetWindowTitle(char *szWindowTitle); void Draw(); };
및 주요 프로그램 :
이//... MyGUIManager *GUIMAN = new MyGUIManager(); MyGUIWindow *FirstWindow = GUIMAN->NewWindow("Hello World"); MyGUIWindow *SecondWindow = GUIMAN->NewWindow("Hello World!!!"); GUIMAN->RegisterWindow(FirstWindow); // ?? GUIMAN->RegisterWindow(SecondWindow); while(Drawing()) { GUIMAN->Draw(); // I wanted this function to be able to call ALL MyGUIWindow instances' Draw() function //... }
그래서 주요 질문은, 어떻게 MyGUIWindow 모든 변수를 확인하는 것입니다 수 WindowCollector 벡터를 통해 제어 할 수 있습니까?
GUIMAN-> RegisterWindow (FirstWindow); // ?? GUIMAN -> RegisterWindow (SecondWindow); 는 참조가 예상 될 때 포인터가 지나가는 것처럼 보입니다.이 문제가 실행중인 것입니까? –
예! 실제로 WindowCollector의 각 멤버가 TargetWindow를 참조하여 RegisterWindow 함수로 다시 밀어 넣기를 원했습니다. –