> Can i do this:
function(std::string = "Hello, world"); ?
If not, is there other way that i can because my compiler (gcc 3.2) is
giving an error;
Thanks,
Anil Mamede
It would be helpful if you said what the error was. You may even be
able to figure it out yourself if you read the error.
But, yes you can provide a default argument for function parameters of
type std::string with gcc. The following compiles with gcc
#include <iostream>
#include <string>
void f(std::string s = "test" )
{
std::cout << s << std::endl;
}
int main(int argc, char* argv[])
{
f();
f("BLA");
return 0;
}
when executed, it produces the following
test
BLA