|
-
July 20th, 2010, 08:48 AM
#2
Re: constructor being ignored in visual studio 2010
 Originally Posted by invaderjolleyolleyman
and I'm creating one dynamically via:
VTXMENU *fish;
fish = new VTXMENU;
not only do my strings end up full of garbage, but the message "created" is never displayed
Why is this happening?
thx
Is VTXMENU a struct or a class? I'm not sure if I correctly interpreted the wording, but it seems like VC++ treats structs and classes differently when you create an object with new as you do.
http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx
 Originally Posted by MSDN
If an object is of a class type and that class has constructors (as in the preceding example), the object can be initialized by the new operator only if one of these conditions is met:
- The arguments provided in the initializer agree with those of a constructor.
- The class has a default constructor (a constructor that can be called with no arguments).
It seems like "class type" does not include a struct and, therefore, your object is not initialized when you call new like this. To make sure the default constructor is called use this instead:
Code:
VTXMENU *fish = new VTXMENU();
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|