这个输出结果是为啥呢?求助!!!

想吃腊肠 想吃腊肠 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

#include <iostream>
using namespace std;

class A
{
private:
    int w,h;
public:
    int getValue() const;
    int getValue();
    A(int x,int y)
    {
        this->h=x;
        this->w=y;
    }
    A()
    {}
};

int A::getValue() const
{
    cout<<"with const"<<endl;
    return w*h;
}

int A::getValue()
{
    cout<<"with none const"<<endl;
    return w*h;
}

void main()
{
    A const a(3,4);
    A b(3,6);   
cout<<a.getValue()<<endl;
cout<<b.getValue()<<endl;
}
这个代码的输出结果为:
wi th const
12
with none const
18


但是将代码中的
cout<<a.getValue()<<endl;
cout<<b.getValue()<<endl;修改为
cout<<a.getValue()<<endl<<b.getValue()<<endl;
输出结果则变为:
with none const
with const
12
18

为什么输出结果会变成这个样子呢?

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
想吃腊肠
Docker 10 成员 28 内容