【发布时间】:2011-09-01 10:14:13
【问题描述】:
我正在编写一个数组类。这个数组类可以再次包含数组作为成员。在实现打印功能时,我需要专业化。
26:template <class T> class array : public vector<T>{
public:
...
string* printToString();
...
};
...
template <class T> string* array<T>::printToString(){
... // generic function
}
template <> inline string* array<double>::printToString(){
... // spezialization for double, works
}
561:template <class U> string* array<array<U>*>::printToString(){
... // does not work
}
最后一个定义产生
src/core/array.h:561: error: invalid use of incomplete type ‘class array<array<T> >’
src/core/array.h:26: error: declaration of ‘class array<array<T> >’
如果重要的话,g++ 版本是 g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3。 有什么想法有什么问题吗?
提前致谢, 托马斯
【问题讨论】:
-
你不应该从标准库容器派生,它们不是为了派生而来的。
-
你真的返回 pointers 到 std::string 吗?
-
另外,
array<array<U>*>不是数组数组。它是一个指针数组。你真的应该摆脱那个*键:+
标签: c++ templates template-specialization specialization