从C ++中相同类中的另一个方法调用方法 [英] Calling a method from another method in the same class in C++

查看:304
本文介绍了从C ++中相同类中的另一个方法调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个类中为 a()写了一个方法(工作正常)。我想在该类中编写另一个方法来调用第一个方法:

I wrote a method (that works fine) for a() in a class. I want to write another method in that class that calls the first method so:

void A::a() {
  do_stuff;
}

void A::b() {
  a();
  do_stuff;
}



我想我可以重写 b / code>所以 b(A obj)但我不想。在java中你可以做 this.a()

I suppose I could just rewrite b() so b(A obj) but I don't want to. In java can you do something like this.a().

我想做 obj.b()其中 obj.a()将作为 obj.b

I want to do obj.b() where obj.a() would be called as a result of obj.b().

推荐答案

这正是你在做什么。

这篇关于从C ++中相同类中的另一个方法调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆