• 如何使用虚拟模板类别,载于该代码:
// test.h
class Base {
public:
virtual std::string Foo() = 0;
virtual std::string Bar() = 0;
};
template <typename T>
class Derived : public Base {
public:
Derived(const T& data) : data_(data) { }
virtual std::string Foo();
virtual std::string Bar();
T data() {
return data_;
}
private:
T data_;
};
typedef Derived<std::string> DStr;
typedef Derived<int> DInt;
// test.cpp
template<typename T>
std::string Derived<T>::Foo() { ... }
template<typename T>
std::string Derived<T>::Bar() { ... }
当我试图使用DStr或DInt时,联系人抱怨说,没有解决的外在问题,即Derived<std:string >:Foo()
和Derived<std:string >:Bar(
;and the Derived<int>
。
我是否对我的法典有过错?
EDIT: Thanks all. It s pretty clear now.