• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

Multimap warning....in VC++ 6.0

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
srik27
Asked:
srik27
  • 7
  • 3
1 Solution
 
AxterCommented:
You can disregard the warnings.

If you're programming is crashing, it has nothing to do with the warnings.
0
 
AxterCommented:
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
 
AxterCommented:
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
Independent Software Vendors: 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!

 
AxterCommented:
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
 
srik27Author Commented:
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
 
srik27Author Commented:
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
 
AxterCommented:
>>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
 
AxterCommented:
>>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
 
AxterCommented:
What compiler are you using?
0
 
srik27Author Commented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now