C++ Can';不为CVOpenGLStextureGetName或CVOpenGLTextureGetName执行typedef

C++ Can';不为CVOpenGLStextureGetName或CVOpenGLTextureGetName执行typedef,c++,ios,c-preprocessor,core-video,C++,Ios,C Preprocessor,Core Video,我在.cpp文件中有一些跨平台代码,它将CVPixelBuffer转换为CVOpenGLESTextureRef/CVOpenGLTextureRef。要使CoreVideo相关功能跨平台,我在头文件中执行以下操作: #ifdef IOS_SHARED_SUPPORT #import <OpenGLES/EAGL.h> #import <CoreVideo/CoreVideo.h> #import <CoreVideo/CVOpenGLESTexture.h>

我在
.cpp
文件中有一些跨平台代码,它将
CVPixelBuffer
转换为
CVOpenGLESTextureRef/CVOpenGLTextureRef
。要使
CoreVideo
相关功能跨平台,我在头文件中执行以下操作:

#ifdef IOS_SHARED_SUPPORT
#import <OpenGLES/EAGL.h>
#import <CoreVideo/CoreVideo.h>
#import <CoreVideo/CVOpenGLESTexture.h>
#import <CoreVideo/CVOpenGLESTextureCache.h>
#endif // IOS_SHARED_SUPPORT

#ifdef MAC_SHARED_SUPPORT
#import <CoreVideo/CoreVideo.h>
#import <CoreVideo/CVOpenGLTexture.h>
#import <CoreVideo/CVOpenGLTextureCache.h>
#import <AppKit/AppKit.h>
#endif // MAC_SHARED_SUPPORT

#ifdef IOS_SHARED_SUPPORT
typedef CVOpenGLESTextureRef CVOpenGLPlatformTexture;
typedef CVOpenGLESTextureCacheRef CVOpenGLPlatformTextureCache;
typedef CVOpenGLESTextureGetName CVOpenGLPlatformTextureGetName; // error!!!
#endif
#ifdef MAC_SHARED_SUPPORT
typedef CVOpenGLTextureRef CVOpenGLPlatformTexture;
typedef CVOpenGLTextureCacheRef CVOpenGLPlatformTextureCache;
typedef CVOpenGLTextureGetName CVOpenGLPlatformTextureGetName; // error!!!
#endif
#ifdef IOS_共享_支持
#进口
#进口
#进口
#进口
#endif//IOS\u共享\u支持
#ifdef MAC_共享_支持
#进口
#进口
#进口
#进口
#endif//MAC\u共享\u支持
#ifdef IOS_共享_支持
typedef CVOpenGLESTextureRef CVOpenGLPlatformTexture;
typedef CVOpenGLESTextureCacheRef CVOpenGLPlatformTextureCache;
typedef CVOpenGLESTextureGetName CVOpenGLPlatformTextureGetName;//错误!!!
#恩迪夫
#ifdef MAC_共享_支持
typedef CVOpenGLTextureRef CVOpenGLPlatformTexture;
typedef CVOpenGLTextureCachef CVOpenGLPlatformTextureCache;
typedef CVOpenGLTextureGetName CVOpenGLPlatformTextureGetName;//错误!!!
#恩迪夫
它说“未知类型名称'CVOpenGLESTextureGetName';您是指'CVOpenGLESTextureRef'?”,尽管包含了
,并且
CVOpenGLESTextureRef
可以在typedef中使用

函数不能进行类型定义吗
你能推荐一些实验吗
提前谢谢

函数不能进行类型定义吗

功能?否。功能类型可能存在别名。您可以使用
decltype
运算符获取函数类型:

typedef decltype(CVOpenGLESTextureGetName) CVOpenGLPlatformTextureGetName;
CVOpenGLPlatformTextureGetName
将成为
GLuint(CVOpenGLESTexture)
的别名,
CVOpenGLESTextureGetName
的函数类型

上面提到的当然不能满足您的需要,因为我怀疑您只是想给函数取另一个名称。您可以使用指向它的
constexpr
指针来执行此操作:

constexpr auto* CVOpenGLPlatformTextureGetName = &CVOpenGLESTextureGetName;

就这样
CVOpenGLPlatformTextureGetName
将在编译时作为初始化函数的“另一个名称”进行计算。

谢谢,它可以工作!我试图删除
constexpr
,这是不允许的。
constexpr
限定符是预处理器保证我不会更改real
CoreVideo
函数的目标代码吗?@Olia\u Pavliuk-它不是预处理器限定符。这是打字系统的一部分。它本质上意味着指针是一个编译时常量表达式,它的计算结果总是相同的地址。