|
-
July 20th, 2010, 05:12 PM
#5
Re: constructor being ignored in visual studio 2010
 Originally Posted by D_Drmmr
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
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();
I'm using a class (not a struct)
I thought I mentioned earlier that putting the parenthesis didn't help
I know this doesn't make sense or I wouldn't be asking about it ^_^
if a thorough example is what you guys want, then you shall receive it...
from main.cpp :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
VTXMENU* root;
root = new VTXMENU;
cout<< root->Command << endl;
delete root;
root = new VTXMENU();
cout<< root->Command << endl;
delete root;
system("pause");
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
from VTXMENU.h :
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class VTXMENU
{
public:
VTXMENU* Submenu;
VTXMENU* Next;
VTXMENU* Previous;
VTXMENU* Parent;
VTXMENU* Base;
char ItemName[40];
char Command[40];
int ItemType;
VTXMENU();
VTXMENU(VTXMENU &old);
~VTXMENU();
VTXMENU operator = (VTXMENU &old);
void Release();
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor from VTXMENU.CPP :
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VTXMENU::VTXMENU()
{
Submenu = NULL;
Next = NULL;
Previous = NULL;
Parent = NULL;
Base = NULL;
ItemType = 0;
ItemName[0] = 0;
Command[0] = 0;
cout<< "initialized\n";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
both time that the contents of Command are displayed, it shows something similar to:
=========================
also, the word 'initialized' is never displayed
none of this seems rational at all
maybe my computer has a hole in its head or something
for some reason I've been having trouble getting this project to build well
I had this same problem a few days ago but it seemed to go away on it's own when I added an arbitrary include to one file, built, removed the include, then built again...
( I tried that again this morning but it didn't help XD )
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
|