A rookie question here. I have noticed something similar with what I am trying to achieve in the cryptic vector class:
iterator begin();
const_iterator begin() const;
I have tried to achieve this with the following implementation:
#include <iostream>
class User
{
public:
class A
{
public:
A(){ std::cout << "A constructor" << std::endl; }
};
class B
{
public:
B(){ std::cout << "B constructor" << std::endl;}
};
public:
A begin() { return A(); }
B begin() const { return B(); }
};
int main()
{
User u;
User::A a = u.begin();
User::B b = u.begin();
}
With this code, I can call the A constructor yet cannot find a way how to call the B constructor.
I get the following error message:
no user-defined conversion from User::A to User::B
Which, I guess, is indicative that the wrong member function is called.
Any tips? :)