return std::string

T

TBass

Quick and stupid question:

I want to replace a function:

const char *
Address()

with
std::string
Address()

Hoping that I will be able to then use the function like so:

std::string mystring = ThisDevice.Address();

Is that a valid use of std::string?
 
V

Victor Bazarov

TBass said:
Quick and stupid question:

I want to replace a function:

const char *
Address()

with
std::string
Address()

Hoping that I will be able to then use the function like so:

std::string mystring = ThisDevice.Address();

Is that a valid use of std::string?

Absolutely!

V
 
T

TBass

Thanks -- I wanted to be sure I wasn't setting myself up for disaster,
especially since the point was to avoid memory errors.
 
D

Daniel T.

TBass said:
Quick and stupid question:

I want to replace a function:

const char *
Address()

with
std::string
Address()

Hoping that I will be able to then use the function like so:

std::string mystring = ThisDevice.Address();

Is that a valid use of std::string?

Yes. I suggest however that you return a const std::string. That way the
returned object will behave more like the built-in types.
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top