0
votes

I have a vector delared in a header file a.h:

// in a.h
class A {
public:
    ...
    std::vector<glm::mat4> transforms;
}

I tried to push_back() an object into it in my a.cpp file:

// in a.cpp
glm::mat4 transform;
transforms.push_back(transform);  // errors here

but I'm getting these errors:

no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=glm::mat4, _Alloc=std::allocator]" matches the argument list and object (the object has type qualifiers that prevent a match)

and

'std::vector>::push_back': 2 overloads have no legal conversion for 'this' pointer

If I try to declare the vector directly inside the a.cpp file then it works:

// in a.cpp
std::vector<glm::mat4> foo;
foo.push_back(transform);   // this works

What is going on? What did I do wrong when I declared the vector in the header file?

1

1 Answers

1
votes

the object has type qualifiers that prevent a match

Focus on this, as this seems to be the problem. It means that you may have made something to do with the vector being or having applied to it a constant type qualifier in your A class. That is the best I can say without more information, as it is obvious that it is not the vector itself that has the problem.

For a clearer and more definite answer you might have to post the exact code you are using.