Dev-cpp中定义对象总是不能通过编译

#include<iostream>#include<string>usingnamespacestd;classstring//声明类string{char*ptr;p... #include<iostream>
#include<string>
using namespace std;
class string//声明类string
{
char*ptr;
public:
string(char*s)
{
ptr=new char[strlen(s)+1];
strcpy(ptr,s);
}
~string()
{delete ptr;}
void print()
{cout<<ptr<<endl;}
};
main()
{
string p1("chen");//定义类string的对象p1,这里就是报错处
{
string p2(" ");//定义类string的对象p2,同上
p2=p1;
cout<<"p2:";
p2.print();//这里也有错,说print不是p2的成员
}
cout<<"p1=";
p1.print();//同上
return 0;
}
所用版本为dev-cpp4.9.9.2
恳请不吝情赐教!
展开
 我来答
ermao0927
2008-09-15 · TA获得超过1190个赞
知道小有建树答主
回答量:853
采纳率:0%
帮助的人:717万
展开全部
你自己定义的类名不能叫string的

C++标准库中有string类了

改成其他名字就好了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式