mzdude
2010-04-05 19:49:10 UTC
We are currently bringing some old VC 6 code forward to VC 2008.
We ran into a problem with the following code snippet. Any ideas
why a CArray of vectors won't work? The easy and obvious solution
is to just make a vector of vectors.
The code appears to function correctly in DEBUG, but will
crash in RELEASE mode.
#include "stdafx.h"
#include <vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
using namespace std;
typedef std::vector<int> TEST_INT_VECTOR;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL,
::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
//This piece of code works fine in debug mode but throws an
// exception in release mode (with default settings).
CArray<TEST_INT_VECTOR, TEST_INT_VECTOR> testArray;
TEST_INT_VECTOR vObj1(1);
testArray.Add(vObj1);
TEST_INT_VECTOR vObj2(1);
testArray.Add(vObj2);
testArray[0].push_back(5);
}
return nRetCode;
}
We ran into a problem with the following code snippet. Any ideas
why a CArray of vectors won't work? The easy and obvious solution
is to just make a vector of vectors.
The code appears to function correctly in DEBUG, but will
crash in RELEASE mode.
#include "stdafx.h"
#include <vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
using namespace std;
typedef std::vector<int> TEST_INT_VECTOR;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL,
::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
//This piece of code works fine in debug mode but throws an
// exception in release mode (with default settings).
CArray<TEST_INT_VECTOR, TEST_INT_VECTOR> testArray;
TEST_INT_VECTOR vObj1(1);
testArray.Add(vObj1);
TEST_INT_VECTOR vObj2(1);
testArray.Add(vObj2);
testArray[0].push_back(5);
}
return nRetCode;
}