c++类和对象问题
这段代码一直显示报错。求大佬指点报错内容如下:
kidult@FreedydeMacBook-Pro MyCpp % cd "/Users/kidult/Desktop/MyCpp/" &
& g++ public&protected&prviate.cpp -o public&protected&prviate && "/Us
ers/kidult/Desktop/MyCpp/"public&protected&prviate
53912
53913
53914
53915
zsh: command not found: protected
exit 127 protected
zsh: command not found: prviate
zsh: command not found: prviate.cpp
53917
zsh: command not found: protected
exit 127 prviate.cpp -o public
- exit 127 protected
zsh: command not found: prviate
zsh: command not found: protected
+ exit 127 protected
kidult@FreedydeMacBook-Pro MyCpp % clang: error: no such file or directory: 'public'
clang: error: no input files
+ exit 1 g++ public
kidult@FreedydeMacBook-Pro MyCpp %
#include<iostream>
#include<string>
using namespace std;
class Person{
public:
//设置姓名
void setName(string name){
m_Name = name;
}
//获取姓名
string getName(){
return m_Name;
}
//获取年龄
//设置情人
private:
//姓名 可读可写
string m_Name;
//年龄 只读
int m_Age;
//情人 只写
stringm_Lover;
};
int main(){
Person p;
p.setName("孙桐");
cout << "姓名:" << p.getName() << endl;
system("pause");
return 0;
} 文件名的问题,代码好像没问题,去掉文件名中的&,或者用_代替试试 lvk 发表于 2022-12-14 21:26
文件名的问题,代码好像没问题,去掉文件名中的&,或者用_代替试试
果然是&的问题!感谢!
页:
[1]