I'm rather stumped. Using MSVC.NET, my code compiles fine, but when I run it, I get a "Debug Assertion Failed! .... File: dgbdel.cpp Line: 52 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" dialog box when it tries to push_back(cSwitch). There's too much code to post everything, so I will attempt to post what I think is relevant.
Code:
class cPort
{
private:
int connectionType;
int connectionIndex;
public:
BOOL connectedToSwitch();
BOOL setConnection(int index, int objectType);
int index();
cPort();
};
class cSwitch
{
private:
cNetwork *network;
int indexOfThis;
protected:
void afunction();
public:
void anotherfunction();
cPort *port;
friend class cSwitch;
cSwitch(int index,cNetwork *networkPointer);
~cSwitch();
};
class cNetwork
{
public:
vector<cSwitch> switches;
int AddSwitch();
friend class cSwitch;
};
I think the implementation details of the classes shouldn't matter for this. When running this code,
Code:
cNetwork networkA; //works fine
cSwitch temp(networkA.switches.size(),&networkA); //works fine
networkA.switches.push_back(temp);
It makes it past the two lines marked //works fine, but gives the error I listed above on the third line. Changing the code to
Code:
vector <cSwitch> networkAswitches;
cSwitch temp(networkA.switches.size(),&networkA);
networkAswitches.push_back(temp);
had no effect; it still couldn't "push_back". When I break, I'm taken to the line
Code:
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
in dbgdel.cpp (in function void operator delete( void *pUserData)), and stepping out, it appears that it was called by
Code:
_CRTIMP int __cdecl _CrtIsValidHeapPointer(
const void * pUserData
)
in dbgheap.c. Clearly, I did not write these two functions (and I can not step out any further). Have I done something wrong, or is this a strange bug in MSVC? Thank you.