Suppose I have:
void foo() {
static Bar bar;
}
Does c++ guarantee me that Bar::Bar() is called on bar, and Bar::~Bar() is never called on bar? (Until after main exits).
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. The first time
foo()is called,Bar barwill be constructed. It will then be available untilmain()finishes, after which point it will be destructed.It’s essentially:
Note I said “essentially”; this probably isn’t what actually happens (though I don’t think it’s too far off).