c++ use default functions in class with same name

2019-03-04 06:22发布

问题:

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