C++ Protected / Public overloads

后端 未结 4 1894
無奈伤痛
無奈伤痛 2021-01-19 05:28

I have a class like this :

class Foo
{
public:
    Foo()
    {
        for(int i = 0; i < 10; ++i)
            v.push_back(i);
    };
    const vector<         


        
4条回答
  •  抹茶落季
    2021-01-19 06:07

    You are close to the solution. The compiler will select the const function if the Foo is also const.

    Foo foo;
    const Foo& cfoo = foo; 
    
    for(int i = 0; i < (int) cfoo.V().size(); ++i)
        cout << cfoo.V().at(i) << endl; 
    

提交回复
热议问题