This is a simplified version of my type system:
#include <string>
#include <vector>
template<typename T>
class Box {
public:
Box(const T& value) : _value(value) {};
private:
T _value;
/* ... */
};
typedef Box<int> Int;
typedef Box<double> Double;
typedef Box<std::string> String;
int main(int argc, char* argv[]) {
String a("abc");
std::vector<String> b = { std::string("abc"), std::string("def") };
// error C2664: 'Box<std::string>::Box(const Box<std::string> &)' : cannot convert argument 1 from 'const char' to 'const std::string &'
std::vector<String> c = { "abc", "def" };
}
While a
and b
compile, c
does not and the reason seems to be that I try to initialize from const char
. This raises two questions:
Why is
b
possible but notc
? Is it because of the nested template instd::vector<Box<std::string> >
?Can I make
c
work without destroying the general boxing mechanism (cf.typedef Box<double> Double
?