Error C2679 using a custom extraction operator [duplicate] - c++

This question already has answers here:
Why does ostream_iterator not work as expected?
(2 answers)
Closed 7 years ago.
I have a custom type, currently placeheld by a std::pair. (It will have more data on it before I'm through...) and am reading it in from a file.
I have cut my code down to:
#include <iostream>
#include <cstdint>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <istream>
using namespace std;
// Show duration isn't an issue, so I can treat all times as integers in the range 0-2400.
using Time = uint16_t;
using Show = pair<Time,Time>; // Placeholder type, for now. This will probably end up as some sort of a std::tuple.
// Build a Show object from its component pieces.
inline Show make_show(Time start, Time finish)
{
return make_pair(start, finish);
}
inline Time& start(Show& show)
{
return show.first;
}
inline Time& finish(Show& show)
{
return show.second;
}
// Get a Show object from a stream.
inline istream& operator>>(istream& is, Show& show)
{
is >> start(show) >> finish(show);
return is;
}
// Get a vector (sorted by start time) of all the shows in an EOF terminated stream
vector<Show> readShows(istream& stream)
{
auto result = vector<Show>{};
// main.cpp, line 58 is the next line.
copy(istream_iterator<Show>(stream), istream_iterator<Show>(), back_inserter(result));
sort(begin(result), end(result));
return result;
}
However, when I compile this I get an error. In essence the error is complaining that when it tries to create an istream_iterator<Show> object it cannot find a suitable operator>>: "error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'Show' (or there is no acceptable conversion)".
This is confusing me, since I do have a function with the signature istream& operator>>(istream& is, Show& show) declared higher up in the program.
This error can be reproduced by compiling with the default Windows compiler in Visual Studio 2013, or by compiling under Clang (which gives "error : invalid operands to binary expression ('istream_type' (aka 'basic_istream<char, std::char_traits<char> >') and 'std::pair<Time, Time>')" - basically the same error with different wording.)
Any help would be welcome.
The full error is given here:
1>------ Build started: Project: ScratchSpace, Configuration: Debug Win32 ------
1> main.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\iterator(256): error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'Show' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(485): could be 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_streambuf<char,std::char_traits<char>> *)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(466): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(void *&)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(448): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(long double &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(430): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(double &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(411): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(float &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(392): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned __int64 &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(373): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(__int64 &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(353): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned long &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(335): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(long &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(317): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned int &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(291): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(int &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(272): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned short &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(237): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(short &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(218): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::_Bool &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(211): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(204): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_ios<char,std::char_traits<char>> &(__cdecl *)(std::basic_ios<char,std::char_traits<char>> &))'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(198): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_istream<char,std::char_traits<char>> &(__cdecl *)(std::basic_istream<char,std::char_traits<char>> &))'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1103): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><char,std::char_traits<char>,_Ty>(std::basic_istream<char,std::char_traits<char>> &&,_Ty &)'
1> with
1> [
1> _Ty=Show
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1093): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,unsigned char &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1086): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,unsigned char *)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1079): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,signed char &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1072): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,signed char *)'
1> while trying to match the argument list '(std::basic_istream<char,std::char_traits<char>>, Show)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\iterator(255) : while compiling class template member function 'void std::istream_iterator<Show,char,std::char_traits<char>,ptrdiff_t>::_Getval(void)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\iterator(222) : see reference to function template instantiation 'void std::istream_iterator<Show,char,std::char_traits<char>,ptrdiff_t>::_Getval(void)' being compiled
1> c:\users\gbenglisha\documents\visual studio 2013\projects\scratchspace\scratchspace\main.cpp(58) : see reference to class template instantiation 'std::istream_iterator<Show,char,std::char_traits<char>,ptrdiff_t>' being compiled
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Looks like ADL lookup is failing you in this case. You are relying on ADL lookup to find your overload for istream and pair (which is not in namespace std::), and it can not be found. Likely has to do with istream_iterator templates (not saying much, I know!). It all works well when using stream >> show; instead of istream_iterator algorithm - so you probably can do a simple loop if you are not fixed on using iterator + copy.
One dreaded way of fixing it would be to define operator >> in namespace std, but this technique is frowned upon for a good reason. There should be other way to help ADL here, but I am not sure how to do this.

Related

Compiler Error (Intel Parallel Studio 2019 with Visual Studio Community 2019)

I have a very simple example
#include <iostream>
int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
If I compile this with Visual Studio Compiler on Visual Studio Community 2019, then it works as expected.
However, when I change the compiler to Intel C++, installed with Intel Parallel Studio 2019, it returns an error
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>Source.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(92): error : expected an identifier
1> !_Is_implicitly_default_constructible<_Uty1>::value || !_Is_implicitly_default_constructible<_Uty2>::value)
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(91): error : not a valid member class or function template declaration
1> constexpr explicit(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(91): error : "explicit" is not allowed
1> constexpr explicit(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(93): error : expected a ";"
1> pair() noexcept(
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : expected an identifier
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : not a valid member class or function template declaration
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(175): error : "explicit" is not allowed
1> constexpr explicit(!is_convertible<const _Other1&, _Ty1>::value // TRANSITION, VSO#946746
1> ^
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include\utility(177): error : expected a ";"
1> pair(const pair<_Other1, _Other2>& _Right) noexcept(is_nothrow_constructible_v<_Ty1, const _Other1&>&&
1> ^
1>
1>compilation aborted for Source.cpp (code 2)
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If I comment out the #include <iostream> and std::cout ~~, which is basically an empty program, then it compiles successfully and runs without error.
My system is
OS: 64bit Windows 10 Enterprise
CPU: AMD Ryzen Threadripper 3970X
I had a similar compiling erro:
c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\include\concepts(47): error : expected ';', near '{'
If I Disable the "bullseye coverage 8.9.44" (compatible til VS 2015) my prog compile with success.

I've got an error for my calculator program C++

I was trying to make a calculator for one of my firsts projects in C++ but I was getting an error.
Here's my code:
#include <iostream>
#include <cmath>
using namespace std;
int a;
int b;
int sum;
int opp;
int yn;
int main()
{
cout << "Enter your first value" << endl;
cin >> a;
cout << "Type the number that corrosponds to your opperation \n 1.add \n 2.subtract \n 3.mutipliy \n 4.divide" << endl;
cin >> opp;
cout << "Choose your last value" << endl;
cin >> b;
return 0;
}
int action()
{
switch(opp)
{
case 1:
sum = a + b;
cout << "Your answer is " << sum << endl;
break;
case 2:
sum = a - b;
cout << "Your answer is " << sum << endl;
break;
case 3:
sum = a * b;
cout << "Your answer is " << sum << endl;
break;
case 4:
sum = a / b;
cout << "Your answer is " << sum << endl;
break;
case >> 5:
cout << "Type the number that corrosponds to your opperation \n 1.add \n 2.subtract \n 3.mutipliy \n 4.divide"
}
cout << "Would you like to use another oppperation? \n Type the number that relates to the answer you want to choose \n 1.Yes \n 2.No" << endl;
cin >> yn;
if (yn = 1)
{
cout << "what would you like your nxt opperation to be? \n 1.add \n 2.subtract \n 3.mutiply \n 4.divide" << endl;
cin >> opp;
return 0;
}
}
I know it is not the best written code but I am more focused on getting it to work.
If it helps the error code I was getting was:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> calculator.cpp
1>c:\users\"my acount"\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\calculator.cpp(12): error C2365: 'yn' : redefinition; previous definition was 'function'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\math.h(1002) : see declaration of 'yn'
1>c:\users\"my account"\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\calculator.cpp(56): error C2059: syntax error : '>>'
1>c:\users\"my account"\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\calculator.cpp(61): error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'double (__cdecl *)(int,double)' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(485): could be 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_streambuf<char,std::char_traits<char>> *)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(466): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(void *&)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(448): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(long double &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(430): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(double &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(411): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(float &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(392): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned __int64 &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(373): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(__int64 &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(353): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned long &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(335): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(long &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(317): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned int &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(291): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(int &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(272): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(unsigned short &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(237): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(short &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(218): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::_Bool &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(211): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(204): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_ios<char,std::char_traits<char>> &(__cdecl *)(std::basic_ios<char,std::char_traits<char>> &))'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(198): or 'std::basic_istream<char,std::char_traits<char>> &std::basic_istream<char,std::char_traits<char>>::operator >>(std::basic_istream<char,std::char_traits<char>> &(__cdecl *)(std::basic_istream<char,std::char_traits<char>> &))'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1103): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><char,std::char_traits<char>,double(int,double)>(std::basic_istream<char,std::char_traits<char>> &&,_Ty (__cdecl &))'
1> with
1> [
1> _Ty=double (int,double)
1> ]
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1093): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,unsigned char &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1086): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,unsigned char *)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1079): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,signed char &)'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\istream(1072): or 'std::basic_istream<char,std::char_traits<char>> &std::operator >><std::char_traits<char>>(std::basic_istream<char,std::char_traits<char>> &,signed char *)'
1> while trying to match the argument list '(std::istream, double (__cdecl *)(int,double))'
1>c:\users\"my account"\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\calculator.cpp(63): error C2659: '=' : function as left operand
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you can try and explain the answer so I can lern from it, as this is my first project.
int yn;
Here you re-declared yn because math.h already has a variable named yn:
extern double yn _PARAMS((int, double));
So rename yn.
case >> 5: is wrong, change it to case 5:
if (yn = 1) will always be true, as its an assignment operation rather Comparison operator (==). Rewrite it as if (yn == 1).
According to the error message, your <cmath> defines (or includes something that defines) something called yn.
And since you're pulling everything from inside std:: to the global namespace (with using namespace std;), your own yn clashes with the yn inside std::.
Solution: stop using using namespace std;.
Well lets just read the output of the compiler.
\calculator.cpp(12): error C2365: 'yn' : redefinition;
previous definition was 'function'
\include\math.h(1002) : see declaration of 'yn'
that first line tells us that there is already of definition of 'yn'
being used. That second line
tells us where: In the math.h file you included. To fix this, choose
another name for 'yn' in your main.cpp file (or you can remove the "using namespace std" line, and append "std::" to the beginning of every call to cout and so on, but I don't think you will know whats really going on there at this stage)
\calculator.cpp(56): error C2059: syntax error : '>>'
This is just saying that there is incorrect syntax, and rightfully so. Take those << out of your last "case", and make it look like every other case you did before that, e.g. "case 5:" This would be just a simple typo on your part.
\calculator.cpp(61): error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'double (__cdecl *)(int,double)' (or there is no acceptable conversion)
This is something I believe is also a result of the redefinition of "yn" and it is treating "yn" as something you don't want it to be, and it doesn't make sense for the >> operator to be used on it. You would use it on a string for instance, as you probably know.
After that it looks like it lists all the ways you can use it, which for the most part isn't immediately important to you.
\calculator.cpp(63): error C2659: '=' : function as left operand
Here you are mistaking the assignment operator (=) for the comparison operator (==). The former assigns values as you have been doing, and the latter produces a boolean of "true" or "false" for usage in, say, if statements. You want the latter, so replace the "=" with "==".
Learn to read through the output of the compiler. It actually says useful stuff, you just have to learn to use it.

What's wrong with map?

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <iterator>
using namespace std;
int main()
{
map<char*, int> m;
int N;
scanf ("%d", &N);
for (int i = 0; i < N; i++)
{
char name[256], s[256];
scanf ("%s", &name);
gets (s);
m[name]++;
}
map<char*, int>::iterator itr;
for (itr = m.begin(); itr != m.end(); itr++)
printf ("%s %d", itr->first, (itr)->second);
}
This program meant to read number of lines then lines, and then output the number of times each word has been repeated in start of lines
for example with this input:
3
Spain Donna Elvira
England Jane Doe
Spain Donna Anna
I expect :
England 1
Spain 2
but I receive :
Spain 3
and I'm sure the the variable name is what it should be each time but something is wrong with the map.
my build log when I changed it to std::string
1>------ Build started: Project: UVa, Configuration: Debug Win32 ------
1> UVa.cpp
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(2245) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(179) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\map(194) : see reference to function template instantiation 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const' being compiled
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\type_traits(743) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1> with
1> [
1> _Ty=std::string
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(1028) : see reference to class template instantiation 'std::is_empty<_Ty>' being compiled
1> with
1> [
1> _Ty=std::less<std::string>
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\map(67) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> c:\users\amiraz\documents\visual studio 2012\projects\uva\uva\uva.cpp(13) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=int
1> ]
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(2245) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(2245) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtree(2245) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1983) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1983) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1983) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1983) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1259) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1259) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1259) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1259) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1075) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1075) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1075) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1075) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(232) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(232) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(232) : see declaration of 'std::operator <'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\utility(232) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef(180): error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
char* are compared as pointers, not as strings. Use std::string instead.
And as P0W mentioned,scanf, printf, gets are C-style. Maps and iterators are C++-style. Don't mix them. Use std::cin, std::cout, std::getline for IO in C++.
If you map with a char* as a key, you're really mapping the with the address of the string, not the string itself as a key. Since your buffer is identically allocated on the stack every time, it will most likely end up at the same address and map to the same value, no matter the content.
Mapping from std::string, the C++ alternative to C strings, will instead automatically use the content of the string as a key.

Code from Book not running - Old syntax or wrong code?

I'm studying Beginning C++ Through Game Programming
In the book I have this example:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main (){
string word1 = "Game";
string word2("Over");
string word3(3, '!');
string phrase= word1 + word2 + word3;
string phrase= word1 + "" + word2 + word3;
cout<< " The phrase is: " << phrase << "\n \n";
cout<< " The phrase has " << phrase.size() << "on it! \n\n";
cout<< " The character at position 0 is " << phrase[0] << "on it! \n\n";
cout<< "Changing the character at position 0 \n\n";
phrase[0] = 'V';
cout << "The phrase now is " << phrase << "\n\n";
for( unsigned int i=0; i < phrase.size() ; i++){
cout << " Character at position "<< i << "is : " << phrase[i] << "\n" ;
}
cout << "The word 'Over' begin at " << phrase.find("Over") << endl;
if (phrase.find("eggplant")==string::npos)
{
cout<<"'Eggplant' is not in the phrase"<<endl;
}
phrase.erase(4,5);
cout<<"phrase now is" << phrase << endl;
phrase.erase();
if(phrase.empty())
{
cout << "phrase is empty" << endl;
}
getchar();
}
When I try to run the code, the debug gives me back this:
1>------ Build started: Project: GameTestExample, Configuration: Debug Win32 ------
1> gameover.cpp
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::_String_iterator<_Mystr> std::operator +(_String_iterator<_Mystr>::difference_type,std::_String_iterator<_Mystr>)' : could not deduce template argument for 'std::_String_iterator<_Mystr>' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(420) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(420) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(420) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(420) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::_String_const_iterator<_Mystr> std::operator +(_String_const_iterator<_Mystr>::difference_type,std::_String_const_iterator<_Mystr>)' : could not deduce template argument for 'std::_String_const_iterator<_Mystr>' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(288) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(288) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(288) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(288) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::move_iterator<_RanIt> std::operator +(_Diff,const std::move_iterator<_RanIt> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1947) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1947) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1947) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1947) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::_Array_iterator<_Ty,_Size> std::operator +(_Array_iterator<_Ty,_Size>::difference_type,std::_Array_iterator<_Ty,_Size>)' : could not deduce template argument for 'std::_Array_iterator<_Ty,_Size>' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1801) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1801) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1801) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1801) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::_Array_const_iterator<_Ty,_Size> std::operator +(_Array_const_iterator<_Ty,_Size>::difference_type,std::_Array_const_iterator<_Ty,_Size>)' : could not deduce template argument for 'std::_Array_const_iterator<_Ty,_Size>' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1662) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1662) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1662) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1662) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1226) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1226) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1226) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1226) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1031) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1031) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1031) : see declaration of 'std::operator +'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1031) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14): error C2676: binary '+' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2374: 'phrase' : redefinition; multiple initialization
1> c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(14) : see declaration of 'phrase'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::_String_iterator<_Mystr> std::operator +(_String_iterator<_Mystr>::difference_type,std::_String_iterator<_Mystr>)' : could not deduce template argument for 'std::_String_iterator<_Mystr>' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(420) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::_String_const_iterator<_Mystr> std::operator +(_String_const_iterator<_Mystr>::difference_type,std::_String_const_iterator<_Mystr>)' : could not deduce template argument for 'std::_String_const_iterator<_Mystr>' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(288) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::move_iterator<_RanIt> std::operator +(_Diff,const std::move_iterator<_RanIt> &)' : could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1947) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::_Array_iterator<_Ty,_Size> std::operator +(_Array_iterator<_Ty,_Size>::difference_type,std::_Array_iterator<_Ty,_Size>)' : could not deduce template argument for 'std::_Array_iterator<_Ty,_Size>' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1801) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::_Array_const_iterator<_Ty,_Size> std::operator +(_Array_const_iterator<_Ty,_Size>::difference_type,std::_Array_const_iterator<_Ty,_Size>)' : could not deduce template argument for 'std::_Array_const_iterator<_Ty,_Size>' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1662) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1226) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const char [1]'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(1031) : see declaration of 'std::operator +'
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(15): error C2676: binary '+' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(17): error C2088: '<<' : illegal for class
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(20): error C2088: '[' : illegal for class
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(23): error C2088: '[' : illegal for class
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(24): error C2088: '<<' : illegal for class
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(28): error C2088: '[' : illegal for class
1>c:\users\victor\documents\visual studio 2012\projects\gametestexample\gametestexample\gameover.cpp(37): error C2088: '<<' : illegal for class
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So, My point is, What's exactly going on? Can't realize if this is problem such as "Old syntax" which I never seen something like that before or if the code is wrong (what I can't believe too, No one would do a fail like that in a book)
I'm using Microsoft Visual Studio Premium 20112 as development environment
Use #include <string> too.

implementation of hash table [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 12 years ago.
i have following code
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <hash_map>
#include <string>
#include <iterator>
#include <ostream>
using namespace std;
struct Equal
{
bool operator()(const char *s1,const char *s2)const
{
return std::strcmp(s1,s2)==0;
}
};
typedef std::hash_multimap<const char*,int,hash<const char*>,Equal>map_type;
void lookup(const map_type&Map,const char *str){
cout<<str<<":";
pair<map_type::const_iterator ,map_type::const_iterator>p=Map.equal_range(str);
for (map_type::const_iterator i=p.first;i!=p.second;++i)
cout << (*i).second<<" ";
}
int maain(){
map_type m;
m.insert(map_type::value_type("H", 1));
m.insert(map_type::value_type("H", 2));
m.insert(map_type::value_type("C", 12));
m.insert(map_type::value_type("C", 13));
m.insert(map_type::value_type("O", 16));
m.insert(map_type::value_type("O", 17));
m.insert(map_type::value_type("O", 18));
m.insert(map_type::value_type("I", 127));
lookup(M,"I");
lookup(M,"0");
lookup(M,"Rn");
return 0;
}
but here is errors
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2903: 'rebind' : symbol is neither a class template nor a function template
1> c:\program files\microsoft visual studio 10.0\vc\include\xhash(170) : see reference to class template instantiation 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled
1> with
1> [
1> _Kty=const char *,
1> _Ty=int,
1> _Tr=std::hash<const char *>,
1> _Alloc=Equal,
1> _Mfl=true
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\hash_map(273) : see reference to class template instantiation 'std::_Hash<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Hmap_traits<const char *,int,std::hash<const char *>,Equal,true>
1> ]
1> c:\users\7\documents\visual studio 2010\projects\hash_tables\hash_tables\hash_tables.cpp(22) : see reference to class template instantiation 'stdext::hash_multimap<_Kty,_Ty,_Tr,_Alloc>' being compiled
1> with
1> [
1> _Kty=const char *,
1> _Ty=int,
1> _Tr=std::hash<const char *>,
1> _Alloc=Equal
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2039: 'rebind' : is not a member of 'Equal'
1> c:\users\7\documents\visual studio 2010\projects\hash_tables\hash_tables\hash_tables.cpp(11) : see declaration of 'Equal'
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2143: syntax error : missing ';' before '<'
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2039: 'other' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\hash_map(27): error C2238: unexpected token(s) preceding ';'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(180): error C2039: 'bucket_size' : is not a member of 'std::hash<_Kty>'
1> with
1> [
1> _Kty=const char *
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(180): error C2065: 'bucket_size' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2039: 'allocator_type' : is not a member of 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>'
1> with
1> [
1> _Kty=const char *,
1> _Ty=int,
1> _Tr=std::hash<const char *>,
1> _Alloc=Equal,
1> _Mfl=true
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2146: syntax error : missing ',' before identifier 'allocator_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(184): error C2065: 'allocator_type' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(186): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(187): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(188): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(189): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(190): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(191): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(192): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(193): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(197): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\list(579) : see declaration of 'std::list'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2146: syntax error : missing ';' before identifier 'iterator'
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C3254: 'std::_Hash<_Traits>' : class contains explicit override 'type' but does not derive from an interface that contains the function declaration
1> with
1> [
1> _Traits=std::_Hmap_traits<const char *,int,std::hash<const char *>,Equal,true>
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2838: 'type' : illegal qualified name in member declaration
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): error C2208: 'std::iterator' : no members defined using this type
1>c:\program files\microsoft visual studio 10.0\vc\include\xhash(198): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.96
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
please help
You have to look at each complier error and fix them one at a time. We can't take a file of code and fix each error. Learning to live and even on occasion love the abusive spouse that is your complier is part of the process.
All your errors seem related to the fact that you're not passing the right template arguments to hash_multimap. Take a look at hash_multimap's documentation. The last parameter, Ăˆqual` should be the allocator, not a function object, check out the 1st error:
c:\program files\microsoft visual studio 10.0\vc\include\hash_map(26): error C2903: 'rebind' : symbol is neither a class template nor a function template
c:\program files\microsoft visual studio 10.0\vc\include\xhash(170) : see reference to class template instantiation 'std::_Hmap_traits<_Kty,_Ty,_Tr,_Alloc,_Mfl>' being compiled
with
[
_Kty=const char *,
_Ty=int,
_Tr=std::hash,
_Alloc=Equal,
_Mfl=true
]
Edit:
If you've looked at SGI's hash_multimap documentation, you'll notice that the hash_map and hash_multimap classes are different between vendors because they are not standard. The next version of the standard comprises standard hashed containers. In the mean time, well, you'll have to write non portable code!