This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Is this template problem in ecgs?




---8<---

#include <iostream>

template<typename T> 
inline
T& 
min(const T& x, const T& y) 
{
  return (x<y)? x:y;
}

int 
main()
{
  int a = 1;
  const int b = 10;

  cout << "a = " << a << ", b = " << b << endl; 
  cout << "min(a,b) = " << min(a,b) << endl;

  min(a,b) = 20;
  cout << "a = " << a << ", b = " << b << endl; 
  cout << "min(a,b) = " << min(a,b) << endl;

  min(a,b) = 30;
  cout << "a = " << a << ", b = " << b << endl; 
  cout << "min(a,b) = " << min(a,b) << endl;
}

/*
10:18am> g++ -Wall test2.cc -otest2
10:18am>./test2
a = 1, b = 10
min(a,b) = 1
a = 20, b = 10
min(a,b) = 10
a = 20, b = 10
min(a,b) = 10

10:18am> gcc -v

gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
(SunOs 5.6)

=== gcc 2.8.1 version ==

10:33:30 advlab$ gcc -V 2.8.1 test2.cc -o test2 -lstdc++
10:33:38 advlab$ ./test2
a = 1, b = 10
min(a,b) = 1
a = 20, b = 10
min(a,b) = 10
a = 20, b = 10
min(a,b) = 10



==== SGI Version ==

Slightly modified about to
<#include <iostreams>
>#include <iostreams.h>
<template <typename T>
>template <class T>
 
===

10:21am> uname 
IRIX64

10:19am> CC test2.cc -o test2sgi
"test2.cc", line 9: error(3514): initial value of reference has excess
          const/volatile qualifiers
    return (x<y)? x:y;
           ^
          detected during instantiation of
                    "int & min(const int &, const int &)" at line 18

1 error detected in the compilation of "test2.cc".

*/

---8<----
--
	"I reserve the right to contradict myself."

Nicholas Lee (Li Peng Ming)  n.lee with math.auckland.ac in nz
Auckland University, New Zealand	





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]