Solved

Creating STL map<string, pair<string, string> >

Posted on 1997-04-14
7
1,122 Views
Last Modified: 2013-12-14
Platform: Win95          Compiler: VC++ 4.2

I have a problem on creating the following map instance using the MS version of STL (internal error reported from the compiler):

typedef pair<string, string>  PairType;
typedef map<string, PairType, ::less<string>, allocator<PairType> >   MapType;

......

MapType     mymap;

To experiment, I changed the types in PairType to be pair<int, int>, it at least compiles okay. But if I switch one of the int back to string, the same symptom occurs.

The following lists my test source codes:


#pragma warning( disable : 4786)

#include <map>
#include <string>

typedef      pair<string, string>      PairType;
typedef      map<string, PairType, ::less<string>, allocator<PairType> >      MapType;


static void      do_test();

int
main()
{
      do_test();
      return 0;
}

static void
do_test()
{
      string      key1("key1"), key2("key999");
      string      data1("data1"), data2("data2"), data3("data3"), data4("data4");

      MapType      mymap;
      mymap[key1] = PairType(data1, data2);
}

0
Comment
Question by:rshek
7 Comments
 
LVL 5

Expert Comment

by:yonat
Comment Utility
You didn't write the compiler error, but I'm guessing that you
forgot to put
    using namespace std;
after the #includes.
0
 

Author Comment

by:rshek
Comment Utility
We don't need to use the namespace std at all. MS version of STL already takes care of it. If the HP version is used, which it wasn't in this case and we'll not consider to use, then an explicit namespace is required.

Please notice the following points in my original question:

1. Changing pair<string, string> to pair<int, int> will work. So it is definitely not a namespace problem.

2. The map key and both the elements in the pair are of the same data type, i.e. string. I keep wondering whether it is not "allowed" to have the data and the key to be the same type (???).



The following encloses the compiler error message:

Compiling...
test_map.cpp
C:\MSDEV\INCLUDE\xtree(153) : fatal error C1001: INTERNAL COMPILER ERROR
  (compiler file 'd:\backend\src\P2\main.c', line 413)
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
Using VC++ 4.2, I have no problem compiling your source using these command lines:

cl /c /GX /O2 yourfile.cpp
cl /c /GX /Od yourfile.cpp
cl /c /GX /O1 yourfile.cpp
cl /c /GX yourfile.cpp

please tell us what command-line switches you're using to cause the internal compiler error message.  (This is the same question you'd be asked if you called Product Support Services, as the error message requests.)

.B ekiM

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rshek
Comment Utility
I have tried using the command line:

cl /c /GX yourfile.cpp

and it works. BUT, to compile it in the Developer Studio it doesn't. However, the program compiles ok in Release settings (but I do require a debug version).

The followings are the project settings:

For debug settings: in C/C++ tab:

/nologo /MLd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /Fp"Debug/test_map.pch" /YX /Fo"Debug/" /Fd"Debug/" /c


For release settings: in C/C++ tab:

/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Release/test_map.pch" /YX /Fo"Release/" /c

0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
The code you've provided here still does't cause an ICE with either of the option sets that you've provided.  I'm not using the /Fp option you've provided, of course, since I don't have the code you're using to generate your PCH file.

This strongly suggests that the problem is because of some code that you still haven't shared with us.

.B ekiM

0
 

Accepted Solution

by:
snemanov earned 100 total points
Comment Utility
Hello! Your code seems syntactically right.I've succeed to compile your code in the MSVC++4.2 with your settings in the debug mode as well as in the release mode. There is only difference I work under NT platform.One of the often occured reasons of ICE is a giant length of full names of objects in STL. The warning 4786 is warns about name truncating into debug info.The line xtree(153) is a constructor of _Tree class. It is the one of the longest names in the STL. Here it is:_Tree<basic_string<char,char_traits<char>,allocator<char>>,pair<basic_string<char,char_traits<char>,allocator<char>>,pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>>,map<basic_string<char,char_traits<char>,allocator<char>>,pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>,less<basic_string<char,char_traits<char>,allocator<char>>>,allocator<pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>>>::_Kfn,less<basic_string<char,char_traits<char>,allocator<char>>>,allocator<pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>>>::_Tree<basic_string<char,char_traits<char>,allocator<char>>,pair<basic_string<char,char_traits<char>,allocator<char>>,pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>>,map<basic_string<char,char_traits<char>,allocator<char>>,pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>,less<basic_string<char,char_traits<char>,allocator<char>>>,allocator<pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>>>::_Kfn,less<basic_string<char,char_traits<char>,allocator<char>>>,allocator<pair<basic_string<char,char_traits<char>,allocator<char>>,basic_string<char,char_traits<char>,allocator<char>>>>>'The other reason of the fault is the reserved word "explicit".It means do not do implicit conversions of input parameters of the function. MSVC++4.2 compiler compile but don't regards this new keyword. It could have a bug in combination with a name length.Well, what to do? Something of this:1) play with compiler options. It should help.2) try to use less robust object than map<string, PairType, ::less<string>, allocator<PairType> > MapType;(if you can)3) to remove explicit keyword from xtree(153);4) to upgrade compiler to 5.0. Many template bugs were corrected in this version.5) try to compile under NT. (It is slightly different compiler code running for Win95 and NT)For the clarity of the experiment close all other applications.

Best wishes, Sergey
0
 

Author Comment

by:rshek
Comment Utility
Thanks for your answer, snemanov. I fact, if I remove the /Zi or /Z7, which flag to generate debug info, the code will compile but I won't be able to debug the code.

Indeed, I got round the problem by declaring a new class and build up a vector of the class instance.


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now