代码如下:
class Student
{
public:
Student();
Student(char n[]);
void print();
void setName();
private:
char name[50];
};
#include<iostream.h>
#include<string.h>
#include"student.h"
void Student::print()
{
cout << "hello, this is "<<name<<"'s first try!" << endl;
}
void Student::setName()
{
char n[50];
cout <<"please enter your name :"<<endl;
cin>>n;
strcpy(name,n);
}
Student::Student(){strcpy(name,"张三");}
Student::Student(char n[]){strcpy(name,n);}
#include<iostream.h>
#include<stdlib.h>
#include"student.h"
int main()
{
Student student,student1("李四");
student.setName();
student1("李四").setName();
student.print();
student1("李四").print();
return 0;
}
错误提示 student1("李四").setName(); student1("李四").print(); 这两行term does not evaluate to a function left of '.setName' must have class/struct/union type 是不是定义构造函数的时候参数不能用char n[ ] 还是那个李四哪里不对 我晕掉了 最近刚开始学C++ 求大神指点
繁花如伊
相关分类