Eclipse shows the following Error on the push_back line:
Invalid arguments '
Candidates are:
void push_back(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)
My Question is, how can i make sure that the vector contains strings and not basic_strings?
I have figured out in another piece of code where i wanted to access this vector that i have troubles compiling it, it seems to know later that it is a basic_string and not a "std::string", in the current context i know that i only will use char but i would like to keep the superclass in there so that in the future i don't have to adjust anything if i swap to w-char ect.
I have already tried casting it to a string but that seems not to work
std::string test = (std::string)tokens[1];
The final goal would be to construct some object with that vector
if(tokens->size() == 3){
TestObject test = new TestObject(tokens[1],)tokens[2])
}
This is the Function i have found on Stackoverflow which was proposed by a stackoverflow user Function Origin
Thanks for helping.
void TestClass::splitString(const std::string &str, std::vector<std::string>* tokens){
boost::char_separator<char> sep(",");
std::string separator;
boost::tokenizer< boost::char_separator<char> > tok(str,sep);
for(boost::tokenizer< boost::char_separator<char> >::iterator it=tok.begin(); it != tok.end(); ++it)
{
tokens->push_back(*it);
}
}
no matching function for call to ‘TestObject::defineX(std::basic_string*)’
accessing with defineX(vector[1].data());
no matching function for call to ‘TestObject::defineX(std::vector >&)’
accessing with defineX(vector[1]);
The definition of the function is declared as the following(maybe this is the issue?):
typedef std::string td_MAP_KEY;
td_MAP_VALUE * TestObject::defineX(td_MAP_KEY key);
I call the method like this, if your keen to compile this, it should work, unfortunately i' am not able to paste the complete code here but the code below should doit:
std::string x = "one,two,three,four"
std::vector<std::string> * splittedString = new std::vector<std::string>;
splitString(x,splittedString);
TestObject * object = new TestObject();
object->defineX(splittedString[1]);