From: Gabor K. <kal...@ms...> - 2005-02-22 22:42:11
<html><div style='background-color:'><DIV class=RTE>
<P><FONT size=2><STRONG><U>Can "class templates" be handled by Version 4.9.9.1 ?</U></STRONG></P>
<P>I am testing a sample from: <A href="http://www.cplusplus.com/doc/tutorial/tut5-1.html">http://www.cplusplus.com/doc/tutorial/tut5-1.html</A></P>
<P><STRONG><U>Here is the source code:</U></STRONG></P>
<P>// class templates<BR>#include <iostream><BR>using namespace std;<BR>//=====================================<BR>template <class T><BR>class pair <BR>{<BR> T value1, value2;<BR> public:<BR> pair<T> (T first, T second) {value1=first; value2=second;}<BR> T getmax ();<BR>};<BR>//=====================================</P>
<P>template <class T><BR>pair<T>::getmax ()<BR>{<BR> T retval;<BR> retval = value1>value2? value1 : value2;<BR> return retval;<BR>}</P>
<P>//=====================================<BR>int main () <BR>{<BR> pair<int> myobject(100, 75);<BR> cout << myobject.getmax();<BR> system("pause");<BR> return 0;<BR>}</P>
<P><STRONG><U>Here are the Messages:</U></STRONG></P>
<P>Compiler: Default compiler</P>
<P>Executing g++.exe...</P>
<P>g++.exe "C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.cpp" -o "C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.exe" -I"C:\Dev-Cpp\include\c++\3.3.1" -I"C:\Dev-Cpp\include\c++\3.3.1\mingw32" -I"C:\Dev-Cpp\include\c++\3.3.1\backward" -I"C:\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" </P>
<P>C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.cpp: In function `int main()':</P>
<P>C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.cpp:26: error: `pair' undeclared (first use this function)</P>
<P>C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.cpp:26: error: (Each undeclared identifier is reported only once for each function it appears in.)</P>
<P>C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.cpp:26: error: expected primary-expression before "int"</P>
<P>C:\Programming\DEV_CPP\CPP_Tutorial\5_00_Templates\class_template.cpp:26: error: expected `;' before "int"</P>
<P>Execution terminated</P>
<P></FONT><BR><BR></P></DIV></div></html>
From: Alfred P. R. <al...@ya...> - 2005-02-22 23:53:18
Yes, they are used throughout the implementation as tcc files.
Look in devcpp/include/c++/3.3.1/bits for examples.
Gabor Kalman <kal...@ms...> wrote:
Can "class templates" be handled by Version 4.9.9.1 ?
I am testing a sample from: http://www.cplusplus.com/doc/tutorial/tut5-1.html
<snip>
Alfred P. Reaud
From: Michal M. <mi...@mo...> - 2005-02-23 01:12:33
Hello,
there are two problems with your code:
1) the line
> pair<T>::getmax ()
should be
T pair<T>::getmax ()
2) the std namespace contains class pair, so because you have
> using namespace std;
at the top of the file it creates conflict. You must either rename your
class or stop using "using namespace std;"
--
Regards,
Michal