2009-09-01 21 views
0

呵呵我很难选择问题标题。但让我解释一下我的问题,使其更清晰。注册类实例以受类的功能控制

我现在用C++编写我自己的GUI库,并带有DirectX包装器。 但是我不知道如何通过调用“manager”类的绘图函数渲染我的游戏窗口。

例如,假设我已经有一个“经理”和“窗口”类。

经理:

​​

窗口:

 
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向量来控制?

+0

GUIMAN-> RegisterWindow(FirstWindow); // ?? GUIMAN-> RegisterWindow(SecondWindow); 看起来像是在期待引用时传递指针,这是您遇到的问题吗? – 2009-09-01 12:21:43

+0

是的!实际上我希望WindowCollector的每个成员在将它推回到RegisterWindow函数时引用targetWindow。 – 2009-09-01 12:25:59

回答

0

是的,基本上可以工作,为什么不试试呢?但我宁愿使用迭代器,而不是你的循环,还有一些自动指针而不是仅仅是new(当前的例子可能会导致内存泄漏)。

其实,从谷歌搜索开始std::vector ...并传递参数作为参考。

0

我不确定我是否正确理解你的问题。你可以在MyGUIWindow的构造函数中调用RegisterWindow()并调用析构函数中的注销等价物。这是否满足您的需求?如果没有,请澄清。