I read that C++ compilers are able to implicitly convert types, when fitting converting constructors or operands are provided. I actually found example code that looks much like this:
class Dog{
private:
string name;
public:
Dog(string n):name(n){} //This as the converting constructor
}
int main(){
Dog d = "rover";
}
Whenever I run this code the compiler throws an error message:
conversion from ‘const char [6]’ to non-scalar type ‘Dog’ requested Dog d = "rover";
When compiling I add the compiler option -std=c++11
, so it shouldn't be about the C++ version, right?
Examples I found on the internet (at least to me) look quite identical, so I have no clue of what is going wrong here.
My input about this topic comes for example from this video:
Convert constructor and overloading operators - thenew moston