+ 1
what is the point of setting 'speed=a' in the 4th line of this code instead if just directly using 'int speed' in the parentheses of the 'setcarspeed' (3rd line) function?
class myClass { public: void setcarspeed (int a){ speed=a; } int getcarspeed(){ return speed; } private: int speed; }; int main() { myClass obj; obj.setcarspeed (40); cout<<obj.getcarspeed ; return 0; }
1 Antwort
+ 1
int a is the parameter of the setcarspeed() function and will only be used inside that function. Same would apply for int speed if you'd use it as a parameter. Speed = a uses the value of your parameter a and makes your class member speed use it for everything that you desire in the instance of your object obj