Classes and variables scope in C++

后端 未结 6 1554
一整个雨季
一整个雨季 2020-12-22 06:32
class car {
    int speed; 
    double position;

    public:
       car(int v,double d);
       int getspeed();
};

int car::getspeed() {
return speed;
}

car::car(         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 06:46

    In the second case, I believe the closest scope variable is used. So, first it checks the local function scope, and finds both speed and position, so the search stops there. In effect, the second constructor isn't actually assigning obje

提交回复
热议问题