分类:
2008-09-17 11:13:21
()
- ()
-- ()
问大侠们一个模板的问题
我定义了一个模板 __________________
template
struct Srep;
Srep *rep;
public:
String();
String(const C*);
String(const String&);
C read(int i) const;
};
template
C* s;//到元素的指针
int sz;//元素个数
int n;
};
template
{
rep=new Srep(0,C());//**************************error
}
int main()
{
String
return 0;
}
在标记的地方报如下错误
error C2514: 'String
E:\OpenCV_Test\childclass\childclass.cpp(6) : see declaration of 'Srep'
E:\OpenCV_Test\childclass\childclass.cpp(48) : while compiling class-template member function '__thiscall String
Error executing cl.exe.
望大侠们赐教
飘飘荡荡的尘埃
对模板不是很了解,不过从错误结果来看,你没有给Srep写个构造函数,而且你申明的这个Srep是结构体还是类呢,如果是结构体的话,new Srep(0,C());就错了,因为结构体没有构造函数,可以直接用new Srep;如果是类则你要实现Srep(0,C());这个构造函数。不然编译器将不知道如何初始化这个对象。
全部时间均为北京时间. 现在时间是15:12 . |
Powered by: vBulletin Version 2.2.8
Translated and hacked by:
Copyright © Jelsoft Enterprises Limited 2000, 2001.