gpt4 book ai didi

c++ - 从 C++ 中同一个类的另一个成员函数中调用成员函数,Objective C

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:12:54 25 4
gpt4 key购买 nike

考虑以下几点:

class A{

//data members

void foo()
{
bar();//is this possible? or should you say this->bar() note that bar is not static
}
void bar()
{

}
}//end of class A

如何从另一个内部调用成员函数?静态函数如何影响“this”的使用。应该在对象上调用函数吗?

最佳答案

Nawaz 是正确的:'this' 是隐含的。一个异常(exception)是如果 foo 是静态函数,因为在静态函数中没有“this”。在那种情况下,您不能使用 bar() 除非 bar() 也是一个静态函数,并且您根本不能使用 this->bar()。

关于c++ - 从 C++ 中同一个类的另一个成员函数中调用成员函数,Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4930309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com