#include<iostream>
#include<string>
using namespace std;
class Person
{
protected:
string name;
char sex;
public:
Person() {};
Person(string name, char sex)
{
this->name = name;
this->sex = sex;
}
void print()
{
cout << "Name:" << name << ", " << "Sex:" << sex << endl;
}
};
int main()
{
Person person("ZhangSan", "M",);
return 0;
}
一些分号和括号的错误
#include<iostream>
#include<string>
#include<iostream>
using namespace std;
class Person
{
protected:
string name;
char sex;
public:
Person() {}
Person(string name, char sex)
{
this->name = name;
this->sex = sex;
}
void print()
{
cout << "Name:" << name << ", " << "Sex:" << sex << endl;
}
};
int main()
{
Person person("ZhangSan", 'M');
person.print();
return 0;
}