I have a class like this :
class Foo { public: Foo() { for(int i = 0; i < 10; ++i) v.push_back(i); }; const vector<
You are close to the solution. The compiler will select the const function if the Foo is also const.
const
Foo foo; const Foo& cfoo = foo; for(int i = 0; i < (int) cfoo.V().size(); ++i) cout << cfoo.V().at(i) << endl;