您的位置:首页 > 编程语言 > C语言/C++

-----------qt-----------C++的模板的使用, ---定义一个模块类--------

2014-01-09 10:44 609 查看
转自:http://qt-project.org/forums/viewthread/14782

If we’re throwing around solutions anyway: you could even create a class template that adds this function to any widget you want, including all stock widgets. :-)

template <class T>

public IDClass<T>: public T {

public:

IDClass(int id, QWidget* parent = 0):

m_id(id),

T(parent)

{}



void setId(int newId) {m_id = newId};

int id() const {return m_id;}



private:

int m_id;

}



typedef IDClass<QLineEdit> IdLineEdit;

typedef IDClass<QPushButton> IdPushButton;

//etc.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: