以与类方法相同的名称调用全局函数吗? [英] Call global function with same name as class method?

查看:106
本文介绍了以与类方法相同的名称调用全局函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些与成员方法同名的全局函数。两者均应在同一范围内使用。我该如何区分它们?约定是否在全局函数中添加前缀 g?我知道它对于全局变量是常规的,但是不确定对于全局函数是否是常规的。

I have global functions which have the same names as member methods. Both are to be used in the same scope. How do I distinguish them? Is adding a prefix 'g' to global functions the convention? I know it is conventional for global variables, but not sure if so for global functions.

推荐答案

您不需要更改要使用它们的函数名称。


如评论所述,您可以完全限定该功能,例如

You don't need to change the function name to use them.
As the comments say, you can fully qualify the function e.g.

void foo()
{
}

class Bar
{
  void foo()
  {
  }

  void wibble()
  {
    ::foo();
  }
};

:: 表示在全局范围内查看

:: means look in global scope

这篇关于以与类方法相同的名称调用全局函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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