提出问题:
如果有这样一个模板:
template <typename T> class Test{
public:
static std::string info;
};
对于以下若干种定义方式,哪些是对的(通过编译)?
template <> string Test<int>::info("123");
template <typename T> string Test<T>::info("123");
template <typename T> string Test<T>::info;
template <> string Test<int>::info;
template <> string Test<int>::info();
template <typename T> string Test<T>::info();
为了不影响大家分析判断,我把答案颜色调成比较浅的颜色,下面即是答案:
- template <> string Test<int>::info("123");//ok
- template <typename T> string Test<T>::info("123");//ok
- template <typename T> string Test<T>::info;//ok
- template <> string Test<int>::info; //error