Are there any issues, like compile time operator, with sizeof associated with new?
Are there any issues, like compile time operator, with sizeof associated with new?
Share
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.
newis an operator so you can overload it for some (or all) of your classes.EDIT: I’ll try to clarify to address @sbi’s comments below.
Consider two classes:
Let’s assume that
new()is a function, and we want to specialize it for theBaseclass and its descendants. We would have the “basic”new()function:Overloaded functions cannot differ by their return types alone, so we can’t do:
We can’t use member functions because they need an existing instance to be called. We could use static member functions:
But the resulting syntax when allocating a instance of
Derivedwould be quite awkward: