主题:string with no type
大虾帮忙找找问题出在哪里?
devcpp编译时出现
14 E:\cpp files\page 23(4).cpp ISO C++ forbids declaration of `String' with no type 程序如下
#include<iostream.h>
#include<string.h>
using namespace std;
class Stirng
{
int length;
char*str;
public:
String(char*);
String(const String &p) ;
void Show(){
cout<<str<<endl;}
};
String::String(char*s){
if(s){
length=strlen(s);
str=new char[length+1];
strcpy(str,s);}
else{
length=0;
str=0;}
}
String::String(const String &p){
length=p.length;
str=new char[length+1];
strcpy(str,p.str);
}
main(){
String str1("This a constructing.");
String str2(str1);
cout<<"str1:";
str1.Show();
cout<<"拷贝后\nstr2:";
str2.Show();
getchar();
}
devcpp编译时出现
14 E:\cpp files\page 23(4).cpp ISO C++ forbids declaration of `String' with no type 程序如下
#include<iostream.h>
#include<string.h>
using namespace std;
class Stirng
{
int length;
char*str;
public:
String(char*);
String(const String &p) ;
void Show(){
cout<<str<<endl;}
};
String::String(char*s){
if(s){
length=strlen(s);
str=new char[length+1];
strcpy(str,s);}
else{
length=0;
str=0;}
}
String::String(const String &p){
length=p.length;
str=new char[length+1];
strcpy(str,p.str);
}
main(){
String str1("This a constructing.");
String str2(str1);
cout<<"str1:";
str1.Show();
cout<<"拷贝后\nstr2:";
str2.Show();
getchar();
}

您所在位置: