Hello,
I just start to learn c++. what I'm using is visual c++ express edition.
here is the source code:
--------------------------------------start
#include <iostream>
using namespace std;
template <class T>
class pair {
T value1, value2;
public:
pair (T first, T second) {
value1=first;
value2=second;
}
T getmax ();
};
template <class T>
T pair::getmax (){
T retval;
retval = value1>value2? value1 : value2;
return retval;
}
int main () {
pair myobject(100,75);
cout << myobject.getmax();
return 0;
}
----------------------------------end
Here is the compiler message:
------------------------------------start
1>------ Build started: Project: classtemp, Configuration: Debug Win32 ------
1>Compiling...
1>classtemp.cpp
1>c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(49) : error C2872: 'pair' : ambiguous symbol
1> could be 'c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(33) : pair'
1> or 'c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(38) : std::pair'
1>c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(57) : error C2244: 'pair<T>::getmax' : unable to match function definition to an existing declaration
1> c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(44) : see declaration of 'pair<T>::getmax'
1> definition
1> 'T pair::getmax(void)'
1> existing declarations
1> 'T pair<T>::getmax(void)'
1>c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(61) : error C2872: 'pair' : ambiguous symbol
1> could be 'c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(33) : pair'
1> or 'c:\program files (x86)\microsoft visual studio 9.0\vc\include\utility(38) : std::pair'
1>c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(61) : error C2514: 'pair' : class has no constructors
1> c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(33) : see declaration of 'pair'
1>c:\users\hongxia\documents\visual studio 2008\projects\classtemp\classtemp\classtemp.cpp(62) : error C2662: 'pair<T>::getmax' : cannot convert 'this' pointer from 'pair' to 'pair<T> &'
1> Reason: cannot convert from 'pair' to 'pair<T>'
1> Conversion requires a second user-defined-conversion operator or constructor
1>Build log was saved at "file://c:\Users\Hongxia\Documents\Visual Studio 2008\Projects\classtemp\classtemp\Debug\BuildLog.htm"
1>classtemp - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
----------------------------------------end
Cannot figure out what is wrong.