Solved

Multimap warning....in VC++ 6.0

Posted on 2004-10-14
10
521 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
  • 7
  • 3
10 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 500 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

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

10 Experts available now in Live!

Get 1:1 Help Now