Is this allowed? :
class A; void foo() { static A(); }
I get signal 11 when I try to do it, but the following works fine:
class A; void foo() { static A a; }
Thank you.
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.
Nope. There is no such thing as an ‘anonymous object’ in C++. There is such a thing as defining an object to type A that is immediately discarded; what you’ve written is an expression that returns an A object that’s never assigned to a variable, like the return code of printf usually is never assigned or used.
In that code, if it worked, you’d be declaring ‘no object’ to be allocated outside the heap. Since there’s no object to allocate, it’s meaningless.