2
为什么我得到不同的出把两只宽度和高度变量在下面的程序输出不一样传递的参数
#include <iostream>
using namespace std;
class my_space {
public :
void set_data(int width,int height) // taking the same name of the variable as the class member functions
{
width = width;
height = height;
}
int get_width()
{
return width;
}
int get_height()
{
return height;
}
private :
int width;
int height;
};
int main() {
my_space m;
m.set_data(4,5); // setting the name of private members of the class
cout<<m.get_width()<<endl;
cout<<m.get_height()<<endl;
return 0;
}
得到下面的程序的输出
sh-4.3$ main
1544825248
32765
如果你打开你的编译器警告,它应该告诉你发生了什么事情。 – Galik