gpt4 book ai didi

c++ - 在 Visual Studio 2010 的 CMake 中定义宏 "disallow copy and assign"

转载 作者:搜寻专家 更新时间:2023-10-31 01:12:25 25 4
gpt4 key购买 nike

到目前为止,一个现有的 C++ 多项目在 QT 中使用 CMake 2.8。我们希望在 Visual Studio 2010 中继续维护它。我在 CMake 中使用选项 -G "Visual Studio 10" 生成了 Visual Studio 项目,但现在我无法编译它们,原因如下:

在项目中,我们使用了一个众所周知的宏,它本身在 this question 中进行了讨论。 .

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)

宏在 CMake 中定义,以便将其作为预处理器定义提供给编译器 (cl.exe):

add_definitions(-DDISALLOW_COPY_AND_ASSIGN\(TypeName\)=\" TypeName(const TypeName&)\; void operator=(const TypeName&)\; \")

Visual Studio 不接受 CMake 的输出,并在代码中使用宏的任何地方抛出编译错误。 CMake 可以为 Visual Studio 2010 正确生成它的正确语法是什么?

最佳答案

不可能在 cl 的命令行上定义函数样式的宏。您可以通过在头文件中包含宏定义并使用 cl 的命令行选项/FI 传递此头文件来解决此问题。或者只是在必要时手动包含它(这可能更干净)。

关于c++ - 在 Visual Studio 2010 的 CMake 中定义宏 "disallow copy and assign",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13767208/

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