使用具有相同声明的类方法调用全局函数 [英] calling a global function with a class method with the same declaration

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

问题描述

我想在C ++类中包装一个C库。对于我的C ++类,我也希望使用这些C函数使用的相同声明:是否可以这样做?

I would like to wrap a C library within a C++ class. For my C++ class I also would like to have the same declaration used by these C function: is it possible to do that?

如果例如我有下面的情况有可能将C函数与C ++函数区分开来吗?

If for example I have the case below how would it be possible to distinguish the C-function from the C++ one? I would like to call the C one off course.

 extern int my_foo( int val ); //

 class MyClass{
    public:
    int my_foo( int val ){
           // what to write here to use
           // the C functions?
           // If I call my_foo(val) it will call
           // the class function not the global one
    }
 }


推荐答案

使用范围解析运算符 ::

Use the scope resolution operator :::

int my_foo( int val ){
    // Call the global function 'my_foo'
    return ::my_foo(val);
}

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

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