Chinaunix首页 | 论坛 | 博客
  • 博客访问: 628116
  • 博文数量: 603
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 4940
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-17 11:04
文章分类

全部博文(603)

文章存档

2011年(1)

2008年(602)

我的朋友

分类:

2008-09-17 11:13:21


()
- ()
-- ()


由 lxjlord 在 2008-07-27 10:25 发表:

问大侠们一个模板的问题

我定义了一个模板
templateclass String{
struct Srep;
Srep *rep;
public:
String();
String(const C*);
String(const String&);
C read(int i) const;
};

template struct String::Srep{
C* s;//到元素的指针
int sz;//元素个数
int n;

};

template String::String()
{
rep=new Srep(0,C());//**************************error
}

int main()
{
String buf;
return 0;
}
在标记的地方报如下错误
error C2514: 'String::Srep' : class has no constructors
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::String(void)'
Error executing cl.exe.
望大侠们赐教

__________________
飘飘荡荡的尘埃


由 ayuilove1 在 2008-07-28 11:59 发表:

对模板不是很了解,不过从错误结果来看,你没有给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.


--------------------next---------------------

阅读(261) | 评论(0) | 转发(0) |
0

上一篇:下一主题

下一篇:下一主题

给主人留下些什么吧!~~