I have a problem with the constructor, which is not working as I'd expect.
If I try to initialize my class like that, it will work and I get a usable object:
vector<float> v;
MyClass<2> a(v);
However, if I try to build a class like below (which should be equivalent) the results are quite unexpected. There is no error message/warning when compiling or running the program. But if you try to use this variable a somewhere and call its methods (for example a.doSomething()), it will crash.
I put some code inside the constructor to notify me if it is used. It turned out that no code inside the constructor was actually executed in this case.
MyClass<2> a(vector<float>());
So I am wondering why this is happening? Is the 2nd declaration illegal?
EDIT: I will post some code of the class
template <int x>
class MyClass {
public:
vector<float> v;
MyClass<x>(vector<float> v1) {
v = v1;
}
};