Function template with an operator

后端 未结 3 1622
花落未央
花落未央 2020-12-05 04:43

In C++, can you have a templated operator on a class? Like so:

class MyClass {
public:
    template
    T operator()() { /* return some T */ }         


        
3条回答
  •  时光取名叫无心
    2020-12-05 05:13

    You need to specify T.

    int i = c.operator()();
    

    Unfortunately, you can't use the function call syntax directly in this case.

    Edit: Oh, and you're missing public: at the beginning of the class definition.

提交回复
热议问题