在自己上调用类方法

Kom*_*tue 1 c++ class

我不确定我尝试做什么是可能的,但是可能有一个技巧可以使它工作.我试图从类函数中调用递归函数,我不知道如何设置类的第一个参数.例如:

Class A{
public:
   A();
   ~A();

   void B();
}

void A::B(){
   C( ****This is where I am unsure);
}

void C(A name){

}
Run Code Online (Sandbox Code Playgroud)

预先感谢您的帮助.

Alo*_*ave 5

看来你想将当前对象的副本传递给方法,所以:

C(*this);
Run Code Online (Sandbox Code Playgroud)

this是一个特殊的指针,它被隐式传递给每个成员函数并指向对象本身.所以你只需要取消引用this.