注册 登录
编程论坛 C++教室

关于重载的小小问题

魅影晓月 发布于 2010-08-06 12:43, 447 次点击
#include <iostream>
using namespace std;
class A
{
public:
    void get(int =4,int =5);
    void set(bool=false);
private:
    int w;
    int h;
};
int main()
{
    A a;
    a.get();
//    a.set();
    return 0;
}
void A::get(int width,int height)
{
   w=width;
   h=height;
   A c;
   c.set();
}
void A::set(bool val)
{
    if(val=false)
    {
        cout<<"val为false时,数值为:"<<w*w<<endl;
    }
    else
    {
        cout<<"当val为trun时,数值为:"<<h*h<<endl;

    }
}





为什么输出的是一条随机数?
如果在main函数中调用set函数则是输出25...怎么回事?
1 回复
#2
魅影晓月2010-08-06 13:04
明白了,不用回答了
1