When I compiled that code, it gives a warning message for function
printString()
:
[Warning] unused parameter 'str' [-Wunused-parameter] |
That is important.
Also, on reading the code, there are several global variables:
1 2
|
string str_to_show = "there is one x in this string\n"; // global variable
list <Entry> phone_book;
|
The first one has the effect of hiding or disguising the logic error in function
printString()
. The second isn't used. I'd remove both those lines.
The corrected function should be:
1 2 3 4
|
void printString (const string& str)
{
cout << str << "\n";
}
|
Note the use of
const
, it's a good idea to use this when passing by reference, where the parameter should not be modified by the function.
The last line:
|
//cout << my_struct.x[0];//not declared
|
you need to declare an object of the required type:
1 2
|
myBigStruct my_struct;
cout << my_struct.x[0];
|
The function
concatenate()
is ok, though you might consider passing the parameters by const reference, this is more efficient:
1 2 3 4
|
string concatenate (const string& aa, const string& bb)
{
return aa+bb;
}
|
One last thing.
When posting your program code, the closing tag [\CODE] should have a forward slash '/', not a backslash '\'.