简体   繁体   English

C ++在类中使用具有相同名称的默认函数

[英]c++ use default functions in class with same name

What would be a good approach to implement a class in c++ like this: 在c ++中实现一个类的好方法是这样的:

Someclass.h: Someclass.h:

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

Someclass.cpp: 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)". 我找不到是否有一个包含“ kill()”,“ sleep(int sec)”的名称空间或类似的名称。 Hope you can help. 希望能对您有所帮助。

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

:: accesses global scope ::访问全局范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM