Visual Studio 2015中的宏参数限制
Macro parameter restrictions in Visual Studio 2015
我正在移植到windows与visual studio 2015的一些代码,构建在linux与gcc。
在VS中,我得到错误错误C2059:语法错误:'+='当使用带有参数"+="的宏DEFOP时,与其他参数相同。这是代码:
#define DEFOP(OP)
Matrix& Matrix::operator OP (const double& val) {
for (int i = 0; i < _n; i++) {
_data[i] OP val;
}
return *this;
}
Matrix& Matrix::operator OP (const Matrix& that) {
if (_rows != _rows || _cols != that._cols) {
throw Exception (String (
"Matrix size mismatch in operation '%s': "
"(%d,%d) vs. (%d,%d).",
__STRING(OP), _rows, _cols, that._rows, that._cols));
}
for (int i = 0; i < _n; i++) {
_data[i] OP that._data[i];
}
return *this;
}
DEFOP(+=);
DEFOP(-=);
DEFOP(*=);
DEFOP(/=);
#undef DEFOP
有人知道如何修改这段代码,使其在VS中构建吗?
由于__STRING
是一个非标准宏,因此并非所有编译器都接受它。使用宏参数作为字符串文字的常见方法是使用#
,即您应该将__STRING(OP)
替换为#OP
相关文章:
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 如何在Visual Studio 2017上将类方法设置为参数并将它们与lambda一起使用?
- Visual Studio 2017 - 无法推断模板参数(使用可变参数模板)
- 切换到 Visual Studio 2019 后,必须在此上下文中展开参数包
- 按值传递的参数在 Visual Studio 2010, C++ 的调试器中显示为通过引用传递
- 如何修复MSVC++(Microsoft Visual studio)中"macro overloading"的可变参数宏相关问题?
- 具有显式参数和大小的可变参数模板.Visual Studio 2013.
- 用于在 Visual Studio 中为整个项目或解决方案定义带有参数的预处理器宏的选项
- 作为模板非类型参数的 C 字符串在 gcc 6.3 中有效,但在 Visual Studio 2017(x64 为 19
- <可变参数模板> Visual Studio 中具有默认值编译错误的模板参数
- 将模板类型参数的映射存储到C++中的矢量中:Visual Studio
- 在Visual Studio调试命令参数中逃脱
- Visual Studio代码:C 编译参数-O
- 模板化使用 无法选择要在 Visual Studio 中用作参数的模板函数
- 值传递的参数在 Visual Studio 2015 x64 调试器中显示不正确
- Visual Studio:管理应用的调试命令行参数
- 在Visual Studio 2017中,通过扩展每个参数包来呼叫基类成员失败
- Enable_if如果使用constexpr函数作为参数,则不在Visual Studio中工作
- C :处理Visual Studio中的每个变异参数