我想创建一个处理整数,双精度和字符串的泛型类。然而,试图实例化模板类时,我得到了以下错误消息:双模板类型?
error: 'double' is not a valid type for a template constant parameter
实例化运作为int类型完全没问题,一样的内部代码,虽然我还没有去到字符串类型尚未。看起来好像这应该没问题,因为你可以实例化向量等。有什么我在这里失踪?
// file forest.h
template<typename NODETYPE> class Forest
{
template<NODETYPE> // Line 15
friend Forest<NODETYPE>& operator+(Forest<NODETYPE>& f1,
Forest<NODETYPE>& f2);
template<NODETYPE> // Line 17
friend ostream& operator<<(ostream& output,
const Forest<NODETYPE>& f1);
template<NODETYPE> // Line 19
friend void outputHelper(ostream& output,
const ForestNode<NODETYPE>& currentNode,
int depth);
/* ... */
};
错误发生如下:
\project 4\forest.h|341|instantiated from here|
\project 4\forest.h|15|error: 'double' is not a valid type for a template constant parameter|
\project 4\forest.h|17|error: 'double' is not a valid type for a template constant parameter|
\project 4\forest.h|19|error: 'double' is not a valid type for a template constant parameter|
@joedillian:“有什么我在这里失踪?” - 是的。你在你的问题中缺少一些代码。如果您可以向我们展示一个能够再现问题的最小代码段,这将非常有帮助。 – 2010-10-31 21:51:17
你想要有模板类型参数,有模板常量参数还是做模板特化?他们是不同的东西。也许你打算做他们其中的一个,并做了另一个意外?请显示一些代码,我们会帮助你弄清楚你正在做什么,以及你应该做什么。 – 2010-10-31 21:53:08
说实话,我真的不知道如何制造这个错误的缩影。上次我发布时,我被告知我没有收到任何帮助,因为我的代码示例太大。现在我被告知我会被忽略,因为我无法提供代码。 : - /我会暂时发布我的全部代码。 – joedillian 2010-10-31 21:59:24