[BUG] forward decleration and namespace (1.1b & snapshot)

Lavoie Philippe lavoie@zeus.genie.uottawa.ca
Thu Oct 22 10:56:00 GMT 1998


A BIG problem here with a very stupid ambiguous call caused by a
namespace. I tried it with both the 19/10/98 snapshot and 1.1b. 

I am using Solaris2.5.1 with an Ultra 1 Sparc.

Here is my test script (named name.cc)


#include <iostream>

namespace Phil {
  template <class T> class Matrix ;
  template <class T> Matrix<T> operator*(const Matrix<T>&,const Matrix<T>&);
  template <class T>
    class Matrix {
      Matrix<T>& operator=(const Matrix<T>&) { cout << "equal" ; }
      friend Matrix<T> operator* <>(const Matrix<T>&,const Matrix<T>&);

  template <class T>
    Matrix<T> comm( const Matrix<T>& a, const Matrix<T>& b);

using namespace Phil ;

template <class T> 
Matrix<T> operator*(const Matrix<T>&,const Matrix<T>&){
  cout << "this one.\n" ;

template <class T>
Matrix<T> comm( const Matrix<T>& a, const Matrix<T>& b){
  Matrix<T> r = a*b ; 
  return r ; 

int main(){
  Matrix<int> a,b,c ; 
  a = comm(b,c) ; 

template class Matrix<int>;
template Matrix<int> operator*(const Matrix<int>&,const Matrix<int>&);
template Matrix<int> comm( const Matrix<int>& a, const Matrix<int>& b);


The result of running the script.

> g++ -o name name.cc
name.cc: In function `int main()':
name.cc:34: call of overloaded `comm (::Phil::::Phil::Matrix<int> &, ::Phil::::Phil::Matrix<int> &)' is ambiguous
name.cc:27: candidates are: comm<int>(const ::Phil::::Phil::Matrix<int> &, const ::Phil::::Phil::Matrix<int> &)
name.cc:15:                 comm<int>(const ::Phil::::Phil::Matrix<int> &, const ::Phil::::Phil::Matrix<int> &)
name.cc: In function `class ::Phil::::Phil::Matrix<int> comm<int>(const class ::Phil::::Phil::Matrix<int> &, const class ::Phil::::Phil::Matrix<int> &)':
name.cc:40:   instantiated from here
name.cc:28: ambiguous overload for `const ::Phil::::Phil::Matrix<int> & * const ::Phil::::Phil::Matrix<int> &'
name.cc:22: candidates are: operator *<int>(const ::Phil::::Phil::Matrix<int> &, const ::Phil::::Phil::Matrix<int> &)
name.cc:5:                 operator *<int>(const ::Phil::::Phil::Matrix<int> &, const ::Phil::::Phil::Matrix<int> &)

Because of this it seems I won't be able to use namespace in my
library :(. 

Please e-mail me if there is a fix for this. Thanks.


PS What's with the ::Phil::::Phil::Matrix<int> ????  Wouldn't
Phil::Matrix<int> be plenty ?

More information about the Gcc-bugs mailing list