I need to know when a C++ class is deallocated if it's inserted into a vector but later goes out of scope because it exits from a function call.
I have written a function called Tokenize that takes a tokens as a vector. Inside the function, I create a C++ class called TokenItem and it's inserted into a tokens vector using push_back function call.
Question #1. Why isn't the TokenItem deallocated once it goes out of the function call? After all, I am able to access it using the following array access:Code:void TokenManager::Tokenize(const string & str, vector<TokenItem>&tokens, string del) ... //The TokenItem is created and inserted into a vector called tokens tokens.push_back( TokenItem(tokenStateInsert, str.substr(lastPos, pos - lastPos))); ...
Question #2 In the push_back function, I also used the str.substr call.Code:for (int x=0; x < sets.size(); x++) { TokenItem aToken= sets[x]; ...
That must create another copy of the string right? When is that string class deallocated?



1Likes
LinkBack URL
About LinkBacks



