Initialization: const type x((function(A)) ? B : C);

C

Charlie Zender

Hi,

I want to initialize a const with the result of a function and an
if test. Is this legal?

main(){
const std::string nvr_USER((std::getenv("USER")) ? std::getenv("USER") :
"");
}

Thanks,
Charlie
 
V

Victor Bazarov

Charlie Zender said:
I want to initialize a const with the result of a function and an
if test. Is this legal?

Yes. Your const is not going to be compile-time const, that's all.

int main(){
const std::string nvr_USER((std::getenv("USER")) ? std::getenv("USER") :
"");

Extra paren...
 

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
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top