【发布时间】:2018-02-27 05:20:48
【问题描述】:
我有class car,我在class App 中使用汽车作为属性。
class Car{
private:
string color;
public:
//setter getter
void setColor(string c){
color = c;
}
string getColor(){
return color;
}
}
和
class App(){
private:
Car car;
public:
App():car(){
}
Car getCar(){
return car;
}
}
这是我的主要应用
int main(){
App app[2];
app[0].getCar().setColor("red")
//WHY RETURN NULL?
cout << app[0]/getCar().getColor();
return 0;
}
setter 运行良好,但为什么 getter 返回 null 就好像对象 app[0] 是重新实例化一样?
谢谢你
【问题讨论】:
-
你的问题有错字吗??
app[0]/getCar()?