default object argument

A

Anil Mamede

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
 
N

Nils Petter Vaskinn

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;

And what was the errot message then? Did you read it?

function (std::string s = "Hello, world");

hth
 
B

Big Brian

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,362
Latest member
ChandaWagn

Latest Threads

Top