jeudi 17 novembre 2022

Same parameter type constructors auto deduction

I have a class whose constructor accepts const string &. When I use auto to define a object with string as parameter. The type deduction result is a string, instead of my custom class. Which rule does apply here?

class AB{
    public:
    AB(const string& a){
        
    }
};

int main()
{
    string a {"a"};
    auto b("b"s);
    
    cout<<a<<endl<<b<<endl;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire