jeudi 20 août 2015

Overloading with “const” at end of function declaration

I have 3 attempts to overload function "begin()"

class Test
{
public:

    //case 1: compiler error
    int begin();
    const int begin();

    //case 2:compiler warning: type qualifiers ignored on function return type
    int begin();
    const int begin() const;

    //case 3: ok
    int begin();
    int begin() const;
};

For the two cases that build successfully, how does the compiler choose which overload is called for begin()?

Aucun commentaire:

Enregistrer un commentaire