Hello,
Consider the fragment:
class C { // A POD-struct
public:
C() { puts("C::C()"); }
};
int main()
{
new C; // new-initializer is omitted
}
C++98 says (5.3.4 #15):
A new-expression that creates an object of type T initializes that object as
follows:
- If the new-initializer is omitted:
- If T is a (possibly cvqualified) non-POD class type (or array
thereof)...
- Otherwise, the object created has indeterminate value...
And then (9 #4):
A POD-struct is an aggregate class that has no non-static data members of
type pointer to member, non-POD-struct, non-POD-union (or array of such
types) or reference, and has no user-defined copy assignment operator and no
user-defined destructor.
However, I've found that both MSVC 7.1 and EDG C front 3.6 generate a
constructor call at the new operator invocation. Can anybody explain why
they don't leave an object created unitialized, as written?
Thank you.
--
Unicals Group -- Development Tools for OEMs
http://www.unicals.com