I have a class like:
class A {
//constructor
A(const unsigned long long x)
{
//some code here
}
}
I also have a templated function like
template<typename T> fcn(T & dest, unsigned long long x)
{
T data(x);
dest = data;
}
When I try to use this function by doing something like:
A data;
unsigned long long x = 11;
fcn<A>(data, x);
I get an error message of the form:
error: non-const lvalue reference to type 'A' cannot bind to a value of unrelated type 'const unsigned long long'
It seems that the compiler is trying to assign x
to data
, instead of invoking the corresponding constructor of A
. How can I fix this in C++11? What am I doing wrong? Thanks
Aucun commentaire:
Enregistrer un commentaire