Home » Community » Newbie corner » Pick Semantics: Passing a Vector to a method
Pick Semantics: Passing a Vector to a method [message #40143] |
Thu, 20 June 2013 21:42  |
NeilMonday
Messages: 15 Registered: May 2013
|
Promising Member |
|
|
I am learning about pick semantics now. Lets assume I wanted to print a Vector of Strings two times. Am I right in assuming that this will not work:
void PrintNames(Vector<String> names)
{
for(int i=0; i<names.GetCount(); i++)
{
//print the name
}
}
int main()
{
Vector<String> myNames;
//add a few Strings to myNames here...
PrintNames(myNames);
//myNames is not valid anymore?
PrintNames(myNames);
}
Instead I will need to do this:
void PrintNames(Vector<String> names)
{
for(int i=0; i<names.GetCount(); i++)
{
//print the name
}
}
int main()
{
Vector<String> myNames;
//add a few Strings to myNames here...
Vector<String> tempNames;
tempNames <<= myNames;
PrintNames(tempNames);
tempNames <<= myNames;
PrintNames(tempNames);
}
|
|
|
Goto Forum:
Current Time: Wed Apr 30 17:33:04 CEST 2025
Total time taken to generate the page: 0.03478 seconds
|