469,293 Members | 1,364 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

Compilation Error of std::map in Win32 Console Project

The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug

This program is developed under Visual Studio .NET 2003 in a Win32 Console Project

// VectorInsert.cpp : Defines the entry point for the console application
/

#include "stdafx.h
#include "VectorInsert.h
#ifdef _DEBU
#define new DEBUG_NE
#endi

#include <vector
#include <string
#include <map

void addToVector(std::vector<std::string>& out_Vector, std::string in_sValue)

// The one and only application objec

CWinApp theApp

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]

int nRetCode = 0

// initialize MFC and print and error on failur
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)

// TODO: change error code to suit your need
_tprintf(_T("Fatal Error: MFC initialization failed\n"))
return 1
std::vector<std::string> loc_Vector1, loc_Vector2

std::map<std::string, std::map<std::string, std::vector<std::string>>> loc_Map
addToVector(loc_Map["GENERIC"]["GENERIC"], "GENERIC")
std::vector<std::string>::iterator loc_Iter
loc_Vector2 = loc_Map["GENERIC"]["GENERIC"]
for (loc_Iter = loc_Vector2.begin(); loc_Iter != loc_Vector2.end(); loc_Iter++)
std::cout << (*loc_Iter).c_str() << std::endl
return nRetCode
void addToVector(std::vector<std::string>& out_Vector, std::string in_sValue)
std::vector<std::string> loc_Vector1, loc_Vector2

loc_Vector1.push_back("Hello World")
loc_Vector1.push_back("How are you?")
loc_Vector1.push_back("Keep on smiling!")

loc_Vector2.push_back("Time to go")
loc_Vector2.push_back("Take care")
loc_Vector2.push_back("Goodbye World!")

loc_Vector1.insert(loc_Vector1.end(), loc_Vector2.begin(), loc_Vector2.end())

std::vector<std::string>::iterator loc_Iter
for (loc_Iter = loc_Vector1.begin(); loc_Iter != loc_Vector1.end(); loc_Iter++)
std::cout << (*loc_Iter).c_str() << std::endl
std::cout << std::endl << "End of addToVector()" << std::endl << std::endl
out_Vector = loc_Vector2

The error displayed is
Compiling..
VectorInsert.cp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1133) : error C2061: syntax error : identifier '_Wherenode
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1130) : while compiling class-template member function 'std::_Tree<_Traits>::_Nodeptr std::_Tree<_Traits>::_Buynode(std::_Tree<_Traits>: :_Nodeptr,std::_Tree<_Traits>::_Nodeptr,std::_Tree <_Traits>::_Nodeptr,const std::_Tree<_Traits>::value_type &,char)
wit

_Traits=std::_Tmap_traits<std::string,std::map<std ::string,std::vector<std::string>>,std::less<std:: string>,std::allocator<std::pair<const std::string,std::map<std::string,std::vector<std:: string>>>>,false

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(77) : see reference to class template instantiation 'std::_Tree<_Traits>' being compile
wit

_Traits=std::_Tmap_traits<std::string,std::map<std ::string,std::vector<std::string>>,std::less<std:: string>,std::allocator<std::pair<const std::string,std::map<std::string,std::vector<std:: string>>>>,false

d:\TestVisualC++\J13 Tests\VectorInsert\VectorInsert\VectorInsert.cpp(3 5) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compile
wit

_Kty=std::string
_Ty=std::map<std::string,std::vector<std::string>
Build log was saved at "file://d:\TestVisualC++\J13 Tests\VectorInsert\VectorInsert\Debug\BuildLog.htm
VectorInsert - 1 error(s), 0 warning(s)
Nov 17 '05 #1
1 6209
Avery Fong wrote:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug?

This program is developed under Visual Studio .NET 2003 in a Win32 Console Project.

// VectorInsert.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "VectorInsert.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <vector>
#include <string>
#include <map>


The #define above is interfering with placement new as used by the STL
implementation. You can delete the #ifdef block, or you can try moving it
below all the #includes. Besides messing up placement new, the #define can
also mess up class-specific operator new. However, it does give you filename
and line number info of the allocation statements, for code which textually
follows the #define, and this can be useful when debugging some types of
heap errors. The #define is not necessary to use the debug heap; it merely
augments the tracking that is done in its absence with filename and line
number info for new-expressions which textually follow its definition.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Woodster | last post: by
1 post views Thread by Antti Granqvist | last post: by
44 posts views Thread by jmoy | last post: by
1 post views Thread by Saeed Amrollahi | last post: by
7 posts views Thread by Torben Laursen | last post: by
4 posts views Thread by Evyn | last post: by
7 posts views Thread by DevNull | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.