For simplicity just pass part of the code.
class A {
public:
std::vector<int> & get(){ return myVector;}
const std::vector<int> & get() const {return myVector;}
private:
std::vector<int> myVector;
}
My question is how to involve overloaded const get method. When I try to create const_iterator and debug code it involves non-const method. Want to understand how it works I use the following snippets
A myA;
myA.get().push_back(1);
for (const auto& v: myA.get()) { } // it involve not const get method
or
std::vector<int>::const_iterator cit = myA.get().begin()
//it involves not const method
or
const std::vector< int > v = myA.get( );
// involves non-const method
or even I create function:
int constVector( const std::vector< int > &constVector )
{
return constVector[0];
}
int b = constVector( myA.get( ) ); // it involves non-const method
What is the purpose of overloaded const method if they are not involved.
And what i doing wrong and how i can involve the const method.