Re: Problem with templates and operator overloading

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

 



Hi Casey,

I recommend taking out your template operator entirely, and put in a specific:

inline double operator * (double lhs, doubler rhs)
{
  return rhs * lhs;
}

Or alternatively (and especially if your operator struct isn't mathematically oriented), avoid overloading operators entirely and use a method invocation instead.

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

Or a functor invocation.

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

HTH,
--Eljay



[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