There’s a feature called anonymous class in C++. It’s similar with anonymous struct in C. I think this feature is invented because of some needs, but I can’t figure out what that is.
Can I have some example which really needs anonymous class?
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.
The feature is there because
structandclassare the same thing – anything you can do with one, you can do with the other. It serves exactly the same purpose as an anonymousstructin C; when you want to group some stuff together and declare one or more instances of it, but don’t need to refer to that type by name.It’s less commonly used in C++, partly because C++ designs tend to be more type-oriented, and partly because you can’t declare constructors or destructors for anonymous classes.