Quick intro I am having an issue when I define a simple class called 'token', that is comprised of two int values, and I make a vector out of this class. I am unable to use the 'push_back'. the compiler tells me my 'does not name a type'
Code example //example of my class definition
class token{
public:
int hi;
int hello;
token(int hi, int hello)
:hi(hi), hello(hello){}
};
//here is how i call and use the class
vector<token> tok;
tok.push_back(1,1);
*disclaimer*So first off, I am a complete noob. I have spent many many hours googling/reading/etc trying to find the answer. Most of the time I haven't been able to fully understand what I was reading, so since I believe my issue is probably very simple I was hoping someone would be able to help me out.
I am using namespace std, please don't tell me that this is bad practice. lol I am just learning how to code, and it makes my life a lot simpler. I am calling in the correct libraries. But I am using SFML.
Please Help So can you please me. I am completely lost. please believe me that I have wasted a better part of a day reading and reading different forums. Thanks :) please keep it simple
push_back require a reference to token object
tok.push_back( token(1,1) );
where emplace_back construct in the vector directly
tok.emplace_back( 1, 1 );
I believe you want the emplace_back
as it is more efficient.