c++ use default functions in class with same name

寵の児 提交于 2019-12-02 19:43:02

问题


What would be a good approach to implement a class in c++ like this:

Someclass.h:

class SomeClass
{
    public:
       SomeClass();
       void kill();
}

Someclass.cpp:

SomeClass::kill(){
    kill();//This would cause an infinit recursion
           //How to fix it?
}

So what I'm trying to do is redeclare a function within my object as a method. I can't find if there is a namespace or something simular, that contains "kill()", "sleep(int sec)". Hope you can help.


回答1:


SomeClass::kill(){
    ::kill();
}

:: accesses global scope



来源:https://stackoverflow.com/questions/25452566/c-use-default-functions-in-class-with-same-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!