如何从类中列出的非const对象调用const函数?

时间:2016-02-04 11:58:26

标签: c++

如何致电void setValue( int i ) const

#include <iostream>
using namespace std;

class Foo
{
public:
    int value()
    {
        return m_value;
    }

    void setValue( int i )
    {
        m_value = i;
        cout<<"void setValue( int i )-------"<<m_value<<i<<endl;
    }

    void setValue( int i ) const
    {
        cout<<"void setValue( int i ) const--"<<i<<endl;
    }

private:
    int m_value;

};

int main() {


    Foo f;
    f.setValue(10);
    const int p = 10;
    f.setValue(p);
    return 0;
}

0 个答案:

没有答案
相关问题