gpt4 book ai didi

c++ - C++ 静态模板函数可以在具有 C 链接的结构中吗?

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:03 26 4
gpt4 key购买 nike

我的头文件中有以下声明:

extern "C" {
struct lfModifier {
template<typename T>
static void ModifyColor_Vignetting_PA (
void *data, float x, float y, T *rgb, int comp_role, int count);
}
}

GCC 可能会正确地提示“错误:带有 C 链接的模板”。但是模板毕竟是静态的。我可以轻松地将它从类中移出到 cpp 文件中。我不喜欢这样做,因为将它放在结构中会增加代码的可读性。

有没有办法在这种情况下使用静态模板?

最佳答案

如果您需要结构中的其他成员具有 C 链接,模板函数可以具有 C++ 链接。

extern "C" {
struct lfModifier {
int val;
void foo();

extern "C++" template<typename T>
static void ModifyColor_Vignetting_PA (
void *data, float x, float y, T *rgb, int comp_role, int count);
}
}

结构成员的

extern C++ 将覆盖结构的 extern C 属性。

关于c++ - C++ 静态模板函数可以在具有 C 链接的结构中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28862878/

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