0

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.

Poehli
  • 307
  • 4
  • 16
  • 1
    Use the scope resolution operator to resolve scopes. By the way, your comment is wrong. It's infinite recursion. – chris Aug 22 '14 at 17:31
  • 1
    "Here it would obviously throw an cannot call member function error" - no, it would recursively call `SomeClass::kill` and core dump. – Christian Hackl Aug 22 '14 at 17:36
  • Yes of cause you're right... I shouldn't just have pasted my trial ;) Updated it – Poehli Aug 22 '14 at 18:57

1 Answers1

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

:: accesses global scope

Piotr Skotnicki
  • 46,953
  • 7
  • 118
  • 160