?
Solved

Multimap warning....in VC++ 6.0

Posted on 2004-10-14
10
Medium Priority
?
576 Views
Last Modified: 2010-04-01
Hi Guys,
I have the following problem:
Below is a section of my code.

// this is in the .h file
typedef      multimap<char*,char*,compare> mtbname;
// this is in the .cpp file
mtbname mtbn;
 mtbn.insert(mtbname::value_type(tabcolname3,maptabname2));

when i try to insert i get the following warning:
----------------------------------------------------------------------------------------------
warning C4786: 'std::_Tree<char *,std::pair<char * const,char *>,std::multimap<char *,char *,compare,std::allocator<char *> >::_Kfn,compare,std::allocator<char *> >::~_Tree<char *,st
d::pair<char * const,char *>,std::multimap<char *,char *,compare,std::allocator<char *> >::_Kfn,compare,std::allocator<char *> >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\xtree(160) : warning C4786: 'std::_Tree<char *,std::pair<char * const,char *>,std::multimap<char *,char *,compare,std::allocator<char *> >::_Kfn,compare,std::allocator<char *> >::_Tree<char *,std
::pair<char * const,char *>,std::multimap<char *,char *,compare,std::allocator<char *> >::_Kfn,compare,std::allocator<char *> >' : identifier was truncated to '255' characters in the debug information
c:\program files\microsoft visual studio\vc98\include\utility(21) : warning C4786: 'std::pair<std::_Tree<char *,std::pair<char * const,char *>,std::multimap<char *,char *,compare,std::allocator<char *> >::_Kfn,compare,std::allocator<char *> >::itera
tor,bool>::pair<std::_Tree<char *,std::pair<char * const,char *>,std::multimap<char *,char *,compare,std::allocator<char *> >::_Kfn,compare,std::allocator<char *> >::iterator,bool>' : identifier was truncated to '255' characters in the debug informa
tion
------------------------------------------------------------------------------------------------------------
and the program crashes when i run in debug mode at this line.
Please kindly tell me what my problem is.
my data has information like

animal animal
animal animal
animal animal

That is the reason why i am using multimap instead of map...is there anything i am overlooking here.
Please tell me what i should do to avoid the warnings.

Thanks in advance
S.

0
Comment
Question by:srik27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 2000 total points
ID: 12314168
You can disregard the warnings.

If you're programming is crashing, it has nothing to do with the warnings.
0
 
LVL 30

Expert Comment

by:Axter
ID: 12314181
The warning is cause by a bug in the compiler.

The warnings can be turned of by adding the following to the top of your source code:
#pragma warning(disable:4786)

For more info, see following links:
http://support.microsoft.com/default.aspx?scid=kb;en-us;167355
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/C4786.asp
0
 
LVL 30

Expert Comment

by:Axter
ID: 12314214
If you're inserting valures into your map object, you need to make sure that you're inserting a buffer that will remain valid through the scope of the map object.

I think what you really want is the following:
typedef     multimap<std::string, std::string> mtbname;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Axter
ID: 12314230
Your original code is using char* pointers, and I don't think you're inserting a string with a valid buffer, or a buffer that will remain valid for the life of the multimap object.
0
 

Author Comment

by:srik27
ID: 12320886
Hi Axter,
thanks a lot for the comments...
I am however not quite clear. I am sure that my char* buffer is right....however what do u mean by should last through out the life of the multimap object?
do u mean that the char* that i am inserting into the multimap should be a const char* ??
If thats what you mean...right now my char* is not a constant....it changes in a for loop --every iteration gives me a new value into char*and i insert this value into my multimap.
I hope i am clear in what i just explained....
I also have another question:

I changed the definition of my multimap according to your advise to
typedef     multimap<std::string, std::string> mtbname;
however now i have to insert strings into my multiset....so
i did the following

char* someval;
char* someotherval;
.
.
.
string str("");
str = (string)someval;
string someotherstr("");
someotherstr=(string)someotherval;

mtbn.insert(mtbname::value_type(str,someotherstr));

Is this right?
Coz i am getting the following errors after i did this:

----------------------------------------------------------------------------------------------------------
 No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        c:\program files\microsoft visual studio\vc98\include\xtree(217) : while compiling class-template member function 'struct std::pair<class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,stru
ct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::multimap<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std
::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator,bool> __thiscall std::_Tree<class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::m
ultimap<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::insert(const struct std::pair<class std::basic_string
<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)'
c:\program files\microsoft visual studio\vc98\include\xtree(222) : error C2064: term does not evaluate to a function
        c:\program files\microsoft visual studio\vc98\include\xtree(217) : while compiling class-template member function 'struct std::pair<class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,stru
ct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::multimap<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std
::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator,bool> __thiscall std::_Tree<class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::m
ultimap<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::insert(const struct std::pair<class std::basic_string
<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)'
c:\program files\microsoft visual studio\vc98\include\xtree(233) : error C2664: '()' : cannot convert parameter 1 from 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
        c:\program files\microsoft visual studio\vc98\include\xtree(217) : while compiling class-template member function 'struct std::pair<class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,stru
ct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::multimap<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std
::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator,bool> __thiscall std::_Tree<class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::m
ultimap<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::insert(const struct std::pair<class std::basic_string
<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)'
c:\program files\microsoft visual studio\vc98\include\xtree(233) : error C2064: term does not evaluate to a function
        c:\program files\microsoft visual studio\vc98\include\xtree(217) : while compiling class-template member function 'struct std::pair<class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,stru
ct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::multimap<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std
::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator,bool> __thiscall std::_Tree<class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::m
ultimap<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class compare,class std::allocator<class std::basic_string<char,s
truct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,class compare,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::insert(const struct std::pair<class std::basic_string
<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > &)'
Error executing cl.exe.
-------------------------------------------------------------------------------------------------------------



Please kindly let me know if you know what i am doing wrong.
Regards,

S
0
 

Author Comment

by:srik27
ID: 12322426
Hi,
Just an Update:

when i try to do

mtbname mtbn;  ------1

it crashes....i dont know why....i tested in the debugger and set break points etc..at this point the code is breaking.

I have a .h file which has the multimap declaration
and the above line 1 is in a function in the .cpp file.

Please kindly tell me what is going wrong....
and one more thing...i am getting the warnings in plenty....i actually used 5 multimaps....and as a result i am getting 115 warnings the same warning mentioned in the above posts.

Thanks in advance
S.
 
0
 
LVL 30

Expert Comment

by:Axter
ID: 12324892
>>do u mean that the char* that i am inserting into the multimap should be a const char* ??

No.
Let me explain via example:

typedef     multimap<char*,char*,compare> mtbname;
mtbname mtbn;

int BadCode1()
{
  char Data1[33] = "Hello World";
  char Data2[33] = "ABC";
  mtbn.insert(mtbname::value_type(Data1,Data2));
}

The function BadCode1 has invalid code, because it's inserting data into the multimap that will not be valid outside of the scope of the function.
Data1 and Data2 only exist in the scope of function BadCode1.  If you call function BadCode1, and then try to access the values entered into the multimap, you will be access invalid data.

int BadCode2()
{
  char *Data1 = "Hello World";
  char *Data2 = "ABC";
  mtbn.insert(mtbname::value_type(Data1,Data2));
}

Sameting with function BadCode2.  The variables only exist within the scope of the function.

int ValidCode1()
{
  char *Data1 = new char[33];
  strcpy(Data1, "Hello World");
  char *Data2 =  new char[33];
  strcpy(Data2, "ABC");
  mtbn.insert(mtbname::value_type(Data1,Data2));
}

Function ValidCode1 has valid code, because the memory allocated for Data1 and Data2 was created via new.
This means the allocated memory will still be valid outside of the scope of the function.
0
 
LVL 30

Expert Comment

by:Axter
ID: 12324898
>>mtbname mtbn;  ------1
>>it crashes....i dont know why....i tested in the debugger and set break points etc..at this point the code is breaking.

Sounds like their is a problem somewhere else in your code.

Can you post more of your code.

The more you show us, the better we can help you find a complete solution.
0
 
LVL 30

Expert Comment

by:Axter
ID: 12324905
What compiler are you using?
0
 

Author Comment

by:srik27
ID: 12339213
Hi Axter,

Thanks a looot for the post and sorry for the late reply.
Yes my program is working fine now.
I do have one last question can you tell me a little bit more about stack and heap and when a variable or an object is stored in a stack and when it is stored in heap....please help me understand this concept clearly both for simple variables and for objects of a class. Please explain in as much detail as possible.
I know that   int* fun() { int x....return &x;} is wrong because x is local variable and it is stored on stack and u try to return the address of a variable which is deallocated which will cause problems etc...can you tell me what is a safe way to return values from functions what happens if int* fun{int *x ...... return x;} is done...is this safe. Examples like the one above that you gave showing bad and good code will be helpful.
I am going ahead and giving you the points.
Thanks a lot.
S.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

762 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