[英]C++ template member variable in templatized class has incomplete type
我在頭文件中有類似以下的代碼:
template<class A>
class List {
private:
QVector<A> _list;
};
其中QVector是標准的QT容器。
當我嘗試在另一個頭文件中創建List類型的變量作為成員變量時,如下所示:
class Model {
private:
List<int *> the_list;
};
我收到以下錯誤:
In instantiation of 'List<int *>':
instantiated from here
error: 'List<A>::_list' has incomplete type
基本上,我想要一個模板化的自定義列表,它使用內部QVector來存儲數據項。
我假設我的語法有點偏,所以任何幫助都會受到贊賞。
在聲明class List { }
之前,請確保#include
d為QVector
的頭文件。 如果省略它,則QVector
是未定義的類型,但由於List
是模板化類,因此編譯器在首次實例化List
之前不會忽略錯誤消息。
#include <QVector>
template<class A>
class List {
private:
QVector<A> _list;
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.