O
Old Wolf
I often see it written here that the declaration
T t = a;
(where 'a' is not of type T) calls the copy-constructor and
is exactly equivalent to
T t(( T(a) ));
However the following code gives me a compiler error:
#include <string>
struct M
{
M(std::string const &s);
};
int main()
{
M a ("Hello");
M b = M("Hello");
M c ( M("Hello") );
M d = "Hello";
return 0;
}
m.cc:13: error: conversion from `const char[6]' to non-scalar type `M'
requested
The error is one the "M d" line, and the other lines compiled
correctly. What's going on?
T t = a;
(where 'a' is not of type T) calls the copy-constructor and
is exactly equivalent to
T t(( T(a) ));
However the following code gives me a compiler error:
#include <string>
struct M
{
M(std::string const &s);
};
int main()
{
M a ("Hello");
M b = M("Hello");
M c ( M("Hello") );
M d = "Hello";
return 0;
}
m.cc:13: error: conversion from `const char[6]' to non-scalar type `M'
requested
The error is one the "M d" line, and the other lines compiled
correctly. What's going on?