|
Hi,
I have a problem using the delete operator on an object. I have been debugging the code for hours and have run out of ideas. My code is similar to the following:
MyClass *MyClassPointer;
MyClassPointer = new MyClass(PointerParam1, PointerParam2);
delete MyClassPointer;
The code "delete MyClassPointer" cause a Debug Assertion saying that line 1044 of dbgheap.c caused an error at the expression _CrtIsValidHeapPointer(pUserData).
I'm completely stumped as to why I can't delete this particular object. I am dynamically allocating and deleting lots of other objects without any problem but this one is causing me grief.
Any ideas as to what I should be looking for ?
Thanks
Ethann Castell
|
|
|
|
|
can you show us destructor for MyClass, it seems that in its destructor you are either trying to delete something that isn't allocated or already deleted.
-Saurabh
|
|
|
|
|
A failed assert in a delete call means you either already freed that memory, or you wrote outside the block of memory allocated for the object. Either way, it's a bug.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Thank you both for your help.
The problem was caused by trying delete a non existant object in the destuctor of a base class. I got put off because I was tracing in the debugger but tracing into the delete does not seem to take you through the destructors. Once I put an explicit breakpoint in the destructor of the base class, the problem became clear.
Thanks again.
Ethann
|
|
|
|
|
this is not a VC question.
my friend gave me a video card - i am a dummy for hardware.
info on card is:
---------------------
MGI G4+ MDH4A32G
FC ... with FCC standards
CE N408 SA
405B
---------------------
do you know what the info mean (conpany etc)?
where to download driver of the video card?
thx
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
This really belongs in the hardware section... but since this is my area of expertise... I'll answer it and let someone else decide to move it.
MGI G4+ MDH4A32G is a Matrox Millennium G400
link to drivers if you need them: http://www.matrox.com/mga/support/drivers/latest/home.cfm[^]
It's pretty old, but it was one of the first dual head (dual screen) video cards produced which made it unique. You'd probably be better off with the lowest end of a current generation at about $50 cash, but that is up to you. It had limited performance even for its time, but for dual screen windows, artists, developers type stuff, it was great. My boss had one of the first ones released and had it for a very long time, and used it primarily for dual-screen Visual C development/debugging, not for graphics. For that it did him well.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
In my header file I am trying to declare and initialize an array,
float front[4][3] = {{1.0f, 1.0f, 1.0f},{-1.0f, 1.0f, 1.0f},{-1.0f,-1.0f, 1.0f},{1.0f,-1.0f, 1.0f}};
I have tried it with and without ',' between the rows.
I have even tried it with only {,} (commas between entry which should just fill up the array in order)
I get syntax error from visual studio .net
Error 1 error C2059: syntax error : '{'
thanks,
kuroiryu
|
|
|
|
|
Tried it on my VS2005 and it seems to compile without a problem. Are you sure the error is at the same line listed above?
gmileka
|
|
|
|
|
I think you doing this inside a class, which is not allowed. Instead initialize array in the constructor.
-Saurabh
|
|
|
|
|
if i declare variable in the header
float front[4][3];
can i still initialize it with {} in the constructor?
front = {{1.0f, 1.0f, 1.0f},{-1.0f, 1.0f, 1.0f},{-1.0f,-1.0f, 1.0f},{1.0f,-1.0f, 1.0f}};
kuroiryu
|
|
|
|
|
Static member arrays (whether const or not) can be initialized in their definitions (outside the class declaration). For example:
class WindowColors
{
public:
static const char *rgszWindowPartList[7];
...
};
const char *WindowColors::rgszWindowPartList[7] = {
"Active Title Bar", "Inactive Title Bar", "Title Bar Text",
"Menu Bar", "Menu Bar Text", "Window Background", "Frame" };
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/specl_32.asp
|
|
|
|
|
in case you dont want to make variable static you can do following in the constructor.
float _front[4][3] = {{1.0f, 1.0f, 1.0f},{-1.0f, 1.0f, 1.0f},{-1.0f,-1.0f, 1.0f},{1.0f,-1.0f, 1.0f}};
memcpy(front, _front, sizeof(float)*12);
-Saurabh
|
|
|
|
|
How do I implement this?
tCircle::tCircle( double fNewX, double fNewY, double fNewRadix )
: cCenter.fX( fNewX ),
cCenter.fY( fNewY ),
nRadix ( fNewRadix )
{
}
I get the error "error C2059: syntax error : '.'" at "cCenter.fX( fNewX )"
regards
hint_54
-- modified at 20:24 Friday 14th April, 2006
|
|
|
|
|
If your class looks like this:
class tCircle
{
double fX;
double fY;
double fRadix
public:
tCircle( double fNewX, double fNewY, double fNewRadix );
};
Constructor implementaiton could be:
tCircle::tCircle( double fNewX, double fNewY, double fNewRadix )
: fX( fNewX ),
fY( fNewY ),
nRadix ( fNewRadix )
{}
gmileka
|
|
|
|
|
No. I have
class tDot {
public:
float fX, fY;
};
class tCircle {
public:
tCircle( void );
tCircle( float, float, float );
tCircle( tDot, float );
public:
float fRadix;
tDot cCenter;
};
I'm having trouble with the 2nd constructor.
Thx
hint_54
|
|
|
|
|
I would add a constructor to tDot.
class tDot
{
public:
float fX, fY;
tDot(float newfX, float newfY){ fX=newfX; fY=newFY; };
};
class tCircle {
public:
tCircle( void );
tCircle( float, float, float );
tCircle( tDot, float );
public:
float fRadix;
tDot cCenter;
};
tCircle::tCircle(double newX, double newY)
: cCenter( newX, newY)
{
}
gmileka
|
|
|
|
|
That's it! thx
hint_54
|
|
|
|
|
You should either use cCenter(fNewX, fNewY), assuming tDot have a constructor accepting two arguments or move cCenter.fX and cCenter.fY within the function body.
-Saurabh
|
|
|
|
|
thx
hint_54
|
|
|
|
|
I am working win WinAPI (not MFC!). Created RichEdit control and it works fine except one small problem. If user select some text in RichEdit control and hit Ctrl+C - nothing goes to clipboard.
Here is creation code:
if (SearchPath(NULL, "RICHED32.DLL", NULL, sizeof(sBuf), sBuf, &s)>0) {<br />
hRE_Lib = LoadLibrary("RICHED32");<br />
} else if(SearchPath(NULL, "RICHED21.DLL", NULL, sizeof(sBuf), sBuf, &s)>0) {<br />
hRE_Lib = LoadLibrary("RICHED21");<br />
} else {<br />
hRE_Lib = NULL;<br />
}<br />
if (hRE_Lib == NULL) {<br />
MessageBox(NULL, "Can not find RichEdit library!", "Error!",<br />
MB_ICONEXCLAMATION | MB_OK);<br />
return 0;<br />
}<br />
<br />
hRichEdit = CreateWindowEx(<br />
WS_EX_CLIENTEDGE,<br />
"RICHEDIT", "",<br />
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |<br />
ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN | ES_READONLY,<br />
1,1,50,100,<br />
hwnd, NULL,<br />
(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),<br />
NULL);<br />
<br />
if(hRichEdit == NULL) {<br />
MessageBox(NULL, "Rich Edit Creation Failed!", "Error!",<br />
MB_ICONEXCLAMATION | MB_OK);<br />
return 0;<br />
}<br />
SendMessage(hRichEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);<br />
Right now, I am thinking about using
SendMessage(hRichEdit, EM_SETEVENTMASK, (WPARAM)NULL, (LPARAM)ENM_KEYEVENTS);
with some code in WndProc which would wait for Ctrl+C and send selected text from RichEdit to clipboard. But may be problem can be fixed more easy?
BTW Ctrl+A already works in my RichEdit control, so I do not understand why Ctrl+C do not work by default. There is only simple text. I am adding it by command SendMessage(hRichEdit, EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)TextBuffer);
|
|
|
|
|
Hi Folks,
I have a little problem..
I created an MFC app wizard application and ran it successfully...
The problem is when i add some header (.h files) along with their implementatio files(.cpp) to the project while compiling follwing error message is displayed...
indicating error in implementation files...
fatal error C1010: unexpected end of file while looking for precompiled header directive
MapNode.cpp
I have seprately compiled and tested these files successfully.. but the problem occurs when i add these files to my project....
Waiting for your response...
Regards,
JinBaba
|
|
|
|
|
|
|
Hi,
Can anyone tell me if it is possible to check if a program is running remotely ( using remote desktop ) or locally.
Is there any win32 API calls to detect this?
regards,
Easen.
|
|
|
|
|
BusaBird wrote: Can anyone tell me if it is possible to check if a program is running remotely ( using remote desktop )...
Sure. Once you have access to the other machine's desktop, simply open Task Manager.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|