Scope of an Arg

  • Thread starter Michael McKnerney
  • Start date
M

Michael McKnerney

Hi,

Can someone answer this simple question:

Given:

string func();

func2( func.c_str() );

When does the string returned from func() go out of scope, after the
call to c_str() or after func2() completes?


thanks,
Mike
 
E

Evan

Michael McKnerney said:
Hi,

Can someone answer this simple question:

Given:

string func();

func2( func.c_str() );

Victor says you probably meant func().c_str() here; I think you
probably meant
string func;
rather than
string func();

The latter does not construct a string called func but declares a
function called func that returns a string. This is why Victor talks
about applying c_str() to a function pointer.
 

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,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top