免責宣告:我對C 非常陌生。
我有一個Container類和一個Item類。這兩個類都是具有相同的Type的通用類:
container.h:
template<typename Type>。
class Container
{
public:
Container(Item<Type> item)。
container.cpp:
#include "container.h"/span>
#include "item.h"
template<typenameType>
Container<Type>::Container(Item<Type> item)
{
}
問題是,在Container的建構式上顯示了一個錯誤:
沒有多載函式 "Container::Container "的實體 匹配指定的型別
我怎樣才能解決這個問題?
uj5u.com熱心網友回復:你需要創建container.tpp(模板檔案) 并將你的類方法的實作寫在 容器.tpp
像這樣:
container.h:
template<typename Type>
class Container
{
public:
Container(Item<Type> item)。
}
#include" container.tpp" //write this at the end of container.h
在container.tpp中
container.tpp:
template<typename Type>
Container<Type>::Container(Item<Type> item)
{
}
uj5u.com熱心網友回復:
通常情況下是這樣做的,container.h
template<typenameType>
class Container
{
public:
Container(const Item<Type> & item)
{
//執行到這里。
}
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/316138.html
標籤:
