[英]initializer list vector constructor
我試圖定義一個類構造函數,該構造函數接受和initializer_list
參數,並使用它來構造包含的向量。
//header
template<typename VertexType, typename IndexType>
class Mesh
{
public:
Mesh(std::initializer_list<VertexType> vertices);
private:
std::vector<VertexType> mVertexData;
};
// cpp
template<typename VertexType, typename IndexType>
Mesh<VertexType, IndexType>::Mesh(std::initializer_list<VertexType> vertices)
{
mVertexData(vertices);
}
編譯失敗,並出現以下錯誤:
error: no match for call to '(std::vector<Vertex,
std::allocator<Vertex> >) (std::initializer_list<NRK::Vertex>&)'
mVertexData(vertices);
不知道我在做什么錯。 有什么提示嗎?
我正在使用QTCreator 5.4.2和MinGW在Windows上進行編譯。
您試圖在完全創建的vector
上調用call-operator( operator()
)。
您應該在ctor-init-list中使用構造函數(首選),或者調用成員函數assign
。
template<typename VertexType, typename IndexType>
Mesh<VertexType, IndexType>::Mesh(std::initializer_list<VertexType> vertices)
: mVertexData(vertices)
{}
順便說一句,您真的確定在該實現文件中定義模板的成員將起作用嗎?
您真的在那里實例化了所有需要的專業化知識嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.