Problem with templates and operator overloading

Casey Goodlett cgoodle@CLEMSON.EDU
Mon Feb 2 16:49:00 GMT 2004


I'm having trouble with the following piece of c++ code.  Is this a bug
in gcc or am I doing something wrong?  The code compiles and runs
without problems in icc.

GCC Version: 3.3.2

struct doubler {
   double operator*(double val) {
      return 2.0 * val;
   }
};

template<typename T> T operator*(double lhs , T rhs) {
   return rhs * lhs;
}

int main() {
   doubler a;
   a * 3.0;
   return 0;
}

Compiling this gives the following error message.

test3.cc: In function `T operator*(double, T)':
test3.cc:7: error: `T operator*(double, T) [with T = double]' must have
an
   argument of class or enumerated type

Thanks.

-- 
Casey Goodlett (cgoodle@clemson.edu)



More information about the Gcc-help mailing list