Problem with templates and operator overloading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx)


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux