Hello, 大家好,我是爱吃香蕉的猴子,VS 2019写C++总会遇到一些报好问题,今天处理一个
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;
class Person {
private:
char* name;
int age;
char* work;
public:
void setName(char* name)
{
this->name = name;
}
int setAge(int age)
{
if (age < 0 || age > 150)
{
this->age = 0;
return -1;
}
this->age = age;
return 0;
}
void printInf(void)
{
printf("name =%s, age = %d\n", name, age);
}
};
int main(int argc, char** arv)
{
Person per;
string str = "cao";
const char* charP = str.c_str();
char* name = const_cast<char*>(charP);
per.setName(name);
per.setAge(2000);
per.printInf();
return 0;
}
Code的搬运工V1.0