我有一個接口和一個存儲序列化對象的類的幾個實現。我想將實現類放入模板類中,以便可以將它們用於多種類型的對象,但是我收到了編譯器錯誤。我可以在C++中編寫模板類的接口
#include <iostream>
template<typename T>
class Interface{
public:
virtual void func(T& c) = 0;
};
class Container{
public:
Container() : dummy(10){}
int dummy;
};
template<typename T>
class Implementation : public Interface{
public:
void func(T& c){
std::cout << "++c.dummy " << ++c.dummy << std::endl;
}
};
int main(){
Container c;
Implementation<Container> i;
i.func(c);
return 0;
}
我在「class Implementation ...」行獲得「錯誤:期望的類名」{'token「之前。
謝謝。
也許是因爲這樣的評論是不歡迎在這個網站。 – 2010-08-10 07:47:17