g++ vs Visual Studio
g++ vs Visual Studio
你能说说为什么Visual Studio编译这段代码(在消息末尾)很好,但g++给了我一个错误:
chapter8_1.cpp:97:50: error: macro "minor" passed 3 arguments, but takes just 1
chapter8_1.cpp:136:36: error: macro "minor" passed 3 arguments, but takes just 1
chapter8_1.cpp:97:11: error: function definition does not declare parameters
chapter8_1.cpp: In member function ‘double Matrices::determinant(double**, int)’:
chapter8_1.cpp:136:17: error: ‘minor’ was not declared in this scope
现在这两个函数在一个struct
,尽管如果我不struct
编译它们(只是独立的函数),那么 g++ 不会给我任何错误,程序工作正常。该程序旨在计算任何方阵的行列式。
法典:
struct Matrices
{
.......
double **minor(double **matrix, int dim, int row) // row stands for the number of column that we are expanding by
{
int dim2 =--dim;
double **minor2;
minor2=new double*[dim2]; // creates minor matrix
for(int i=0; i<dim2; ++i)
minor2[i]=new double[dim2];
for(int hhh=0; hhh<dim2; ++hhh)
{
int bbb=0;
for(int aaa=0; aaa<dim2+1; ++aaa) // initializing the minor matrix
{
if (aaa==row)
continue;
else
{
minor2[hhh][bbb]=matrix[hhh+1][aaa];
++bbb;
}
}
}
return minor2;
}
double determinant(double **mat, int dim)
{
double det=0;
if(dim==1)
det=mat[0][0];
if(dim==2)
det=mat[0][0]*mat[1][1]-mat[0][1]*mat[1][0];
else
{
double ***setOFmat; // pointer that points to minors
setOFmat=new double**[dim];
for (int ddd=0; ddd<dim; ++ddd) // ddd represents here the number of column we are expanding by
setOFmat[ddd]=minor(mat, dim, ddd);
for (int ddd=0; ddd<dim; ++ddd) // ddd srepresents the same here
{
det= det + pow(-1.0,ddd)*mat[0][ddd]*determinant(setOFmat[ddd], dim-1); // actual formula that calculates the determinant
}
}
return det;
}
您应该更仔细地阅读错误消息:-)
chapter8_1.cpp:97:50:错误:宏"次要"传递了 3 个参数,但只需要 1 个参数
这意味着gcc
认为minor
是某种描述的宏,因此对行进行预处理:
double **minor(double **matrix, int dim, int row)
可能会很麻烦。
我会用gcc -E
编译它以获得预处理器输出,这样你就可以知道:
- 它如何破坏你的线路;和
- 希望在哪里定义
minor
宏。
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 不同的Visual Studio版本中缺少.dll
- 用Visual Studio在C++中嵌入Julia
- Visual Studio 2017循环自动向量化问题
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- Visual Studio在尝试读取resource.txt文件时崩溃
- Visual Studio 2017 不允许我创建 C++ 专用模板