Is it possible to overload C++ class operators in the static context? e.g.
class Class_1{ ... }
int main()
{
Class_1[val]...
}
Is it possible to overload C++ class operators in the static context? e.g.
class Class_1{ ... }
int main()
{
Class_1[val]...
}
If you are looking for metaprogramming using the built-in operator: Such a thing isn't possible - the built-in operators operate on runtime values, not on compile time values.
You may use
boost::mpl
for that, and instead of using the built-in operators, use its templates, likeat
forop[]
,plus<a, b>
forop+
etc.I don't believe it's possible, though I could be wrong on this front. I'd like to ask why you'd want to do this though. Rather than performing operations on a class instead of instances, perhaps you just require one instance throughout your application? In this case, you should probably be using the singleton pattern.
If you mean the operator operates on a class, the No. That does not make sense, it is like saying
operator +
may operator onint
ordouble
. Operators are syntactic sugar for functions and they operate on varibles(values) not types.No, operators cannot be static members of a class. Use a regular static function instead.