C++ static operator overloading

后端 未结 4 808
无人及你
无人及你 2021-02-15 17:06

Is it possible to overload C++ class operators in the static context? e.g.

class Class_1{ ... }
int main()
{

    Class_1[val]...

}
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-15 17:28

    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.

提交回复
热议问题