EDIT: aList was being referenced as a pointer in this version of my code, but not in my current version which still has the same problem.
I had this code perfectly working before trying to split it in an interface file and an implementation file. But when I splitted it, the compiler tells me I’m calling push_back() with incorrect parameters. So I understand it cannot reference the type of the object I’m pushing it, although it’s the same (afaik, of course :D).
#ifndef _MYHEADER_HPP_
#define _MYHEADER_HPP_
class A{
public:
std::string someString;
};
class B{
public:
std::vector<A> aList;
public:
void addA();
};
#endif /* _MYHEADER_HPP_ */
//implementation file
#include <string>
#include <vector>
#include "myheader.hpp"
void B::addA(){
A a;
a.someString = "Hola";
// Here compiler says : Invalid arguments 'Candidates are: void push_back(const A &)' line 18 Semantic Error
aList.push_back(a);
}
AFAIK, std::vector always do a copy of the object to push, and that copy gets stored into the vector, so I think it’s not a problem of ‘a’ being stack allocated, am I right?
What I’m doing wrong?
Thanks.
Ok, after more than 3 hours looking for the root of the problem, I found that Eclipse CDT IDE had a corrupted cache file about my code. So, compiling from command line was everything fine, I had to delete that cache file and then Eclipse reported no errors.