Direct assignment with operator=

Hello guys :)

I created a class, and defined operator= as follows:

1
2
template <typename T>
MyClass& operator=(const vector<T> src);


but the problem is, when I create my class's object, I can't do the following:

1
2
3
vector<double> x;
x.push_back(10.);
MyClass c = x;


But I have to do it this way:

1
2
3
4
vector<double> x;
x.push_back(10.);
MyClass c;
c = x;


the former doesn't compile! it says in Intel compiler:

error: no suitable user-defined conversion from "std::vector<double, std::allocator<double>>" to "MyClass" exists

Could you guys tell me why it doesn't compile? what am I missing here?

Thank you for any efforts :)
The first is calling the constructor MyClass(std::vector<T> rhs). It's the same as writing MyClass c(x);
Ah! thank you so much, pal! by defining the constructor it worked ^^
Topic archived. No new replies allowed.