This is the mail archive of the gcc-bugs@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]

Template problem on DEC Alpha


I'm not sure if this is a EGCS bug or just wrong C++-code.

System:   DEC Alpha Server 1000
Os:       Digital Unix 4.0D
Compiler: gcc version egcs-2.92.13 19981005 (gcc2 ss-980609 experimental)

The following code-example is not really useful but illustrates the problem: 
an explicitly instanciated template-function which is friend of class Base has 
no access to the private parts of Base. The code compiles fine with egcs1.0.3a 
but fails with the above version.


template.cpp:
-------------------------------------------------------

#include <iostream>

template <class T> class Base;
template <class T> ostream& operator<<(ostream&, const Base<T>& );

template<class T> class Base
{
public:
  Base( int a ) : bla( a ) {}

  friend ostream& operator << <>(ostream&, const Base<T>& );

private:
  int bla;
};


template<class T>
ostream& operator<<(ostream& os, const Base<T>& bs)
{
  os << "(Usual) " << bs.bla;
  return os;
}

/* Funktion causing trouble... */
ostream& operator<<(ostream& os, const Base<double>& bs)
{
  os << "(Double) " << bs.bla;       // <-------
  return os;
}


int main( void )
{
  Base<int> a( 2 );
  Base<double> b( 3 );

  cout << "a: " << a << endl;
  cout << "b: " << b << endl;
  
  return 0;
}

-------------------------------------------------------

Thanks

Martin




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