I need to identify what properties(strings) are processed by a method. So, I have designed my method as below.
void method1( std::vector<String> * myVector )
{
myVector = new std::vector<String>();
//do something;
myVector->push_things;
}
So, I would call method1 from topMethod() like this.
topMethod()
{
std::vector<String> * aVector = 0;
method1( aVector );
//process aVector to identify its contents;
}
Now, the vector myVector in method1() is getting populated fine. But its contents are unable at the caller method i.e., topMethod(). I’m not sure how they are getting freed. I feel that I’m allocating using new, so they should ideally be present at the caller location after the call..
Please provide your thoughts on what is going wrong.
You should pass the pointer to vector by reference.
You are allocating to a copy of the pointer to vector you passed not the pointer you passed.
This should fix it.