gpt4 book ai didi

c++ - 在 Objective C 中包含模板化 C++

转载 作者:太空狗 更新时间:2023-10-29 23:47:57 24 4
gpt4 key购买 nike

我正在尝试将带有大量模板的 C++ 库包含到 Objective-C 应用程序中。

它似乎永远被共享库中的一些内联语句阻塞:

template <class T>
inline T MIN(T a, T b) { return a > b ? b : a; }

template <class T>
inline T MAX(T a, T b) { return a > b ? a : b; }

产生输出:

expected unqualified-id before '{' token
expected `)' before '{' token

我正在使用选项进行编译。

g++ -x objective-c++ -Wall -O3 -I. -c demod_gui.m -o demod_gui

所有其他模板似乎都可以正常编译,知道这里可能有什么问题吗?在此先感谢您的帮助。

最佳答案

Foundation/NSObjCRuntime.h 中已经定义了宏MINMAX

#if !defined(MIN)
#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
#endif

#if !defined(MAX)
#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
#endif

所以你的定义变成了

template <class T>
inline T ({ __typeof__(T a) __a = (T a); __typeof__(T b) __b = (T b); __a < __b ? __a : __b; }) { return a > b ? b : a; }

这显然是无效的。

为什么不使用 std::maxstd::min?

关于c++ - 在 Objective C 中包含模板化 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3207712/

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