c++,这是错误显示:error C2059: syntax error : 'string',请问哪里错了?
#include<iostream>usingnamespacestd;classBusinessManager{private:charid[10];charname[...
#include<iostream>
using namespace std;
class BusinessManager
{
private:
char id[10];
char name[10];
int age;
public:
BusinessManager(char s1[10],char s2[10],int s3)
{
*strcpy(id,s1);
*strcpy(name,s2);
age = s3;
cout<<"Position:BusinessManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by constructor."<<endl;
}
~BusinessManager()
{
cout<<"Position:BusinessManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by destructor."<<endl;
}
};
class TechnicalManager
{
private:
char id[10];
char name[10];
int age;
public:
TechnicalManager(char s1[10],char s2[10],int s3)
{
*strcpy(id,s1);
*strcpy(name,s2);
age = s3;
cout<<"Position:TechnicalManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by constructor."<<endl;
}
~TechnicalManager()
{
cout<<"Position:TechnicalManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by destructor."<<endl;
}
};
class Employee
{
private:
char id[10];
char name[10];
int age;
public:
Employee(char s1[10],char s2[10],int s3)
{
*strcpy(id,s1);
*strcpy(name,s2);
age = s3;
cout<<"Position:Employee id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by constructor."<<endl;
}
~Employee()
{
cout<<"Position:TechnicalManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by destructor."<<endl;
}
};
class Team
{
public:
Team();
private:
BusinessManager businessManager1("123","John",43);
TechnicalManager technicalManager1("234","Peter",42);
Employee employee1("345","James",32);
Employee employee2("456","Paul",23);
Employee employee3("567","Mary",27);
Employee employee4("678","Lily",31);
Employee employee5("789","Lucy",25);
};
int main()
{
Team team1;
return 0;
} 展开
using namespace std;
class BusinessManager
{
private:
char id[10];
char name[10];
int age;
public:
BusinessManager(char s1[10],char s2[10],int s3)
{
*strcpy(id,s1);
*strcpy(name,s2);
age = s3;
cout<<"Position:BusinessManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by constructor."<<endl;
}
~BusinessManager()
{
cout<<"Position:BusinessManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by destructor."<<endl;
}
};
class TechnicalManager
{
private:
char id[10];
char name[10];
int age;
public:
TechnicalManager(char s1[10],char s2[10],int s3)
{
*strcpy(id,s1);
*strcpy(name,s2);
age = s3;
cout<<"Position:TechnicalManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by constructor."<<endl;
}
~TechnicalManager()
{
cout<<"Position:TechnicalManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by destructor."<<endl;
}
};
class Employee
{
private:
char id[10];
char name[10];
int age;
public:
Employee(char s1[10],char s2[10],int s3)
{
*strcpy(id,s1);
*strcpy(name,s2);
age = s3;
cout<<"Position:Employee id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by constructor."<<endl;
}
~Employee()
{
cout<<"Position:TechnicalManager id:"<<id<<" name:"<<name<<" age:"<<age<<"This is printed by destructor."<<endl;
}
};
class Team
{
public:
Team();
private:
BusinessManager businessManager1("123","John",43);
TechnicalManager technicalManager1("234","Peter",42);
Employee employee1("345","James",32);
Employee employee2("456","Paul",23);
Employee employee3("567","Mary",27);
Employee employee4("678","Lily",31);
Employee employee5("789","Lucy",25);
};
int main()
{
Team team1;
return 0;
} 展开
展开全部
BusinessManager businessManager1("123","John",43);
TechnicalManager technicalManager1("234","Peter",42);
Employee employee1("345","James",32);
Employee employee2("456","Paul",23);
Employee employee3("567","Mary",27);
Employee employee4("678","Lily",31);
Employee employee5("789","Lucy",25);
你的这段代码有问题。因为还是在申明变量,并没有进行初始化,初始化要么放在构造函数中,或者调用特定的初始化函数,但是在申明变量的时候一定不能这样中,因为team还没有确定,怎么能够确定他的成员呢!!打个比方,没有确定母体,就确定了母体的孩子,这是不可能的
TechnicalManager technicalManager1("234","Peter",42);
Employee employee1("345","James",32);
Employee employee2("456","Paul",23);
Employee employee3("567","Mary",27);
Employee employee4("678","Lily",31);
Employee employee5("789","Lucy",25);
你的这段代码有问题。因为还是在申明变量,并没有进行初始化,初始化要么放在构造函数中,或者调用特定的初始化函数,但是在申明变量的时候一定不能这样中,因为team还没有确定,怎么能够确定他的成员呢!!打个比方,没有确定母体,就确定了母体的孩子,这是不可能的
展开全部
语法错误。要么是
string
标识不正确,要么就是string头文件没有包含进去
string
标识不正确,要么就是string头文件没有包含进去
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议把char类型改为string 很久没碰c++了不确定。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <string >
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String 应该是大写的八
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询