0
我有以下模板函數變量並沒有在此範圍內的gcc錯誤聲明
//This is a very naive implementation, but it will do
template<class T>
T determinant(const std::vector<std::vector<T>> &matrix)
{
sci::assertThrow(square(matrix), sci::err());
if (matrix.size() == 1)
return matrix[0][0];
else if (matrix.size() == 2)
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
else
{
double result = 0;
std::vector<std::vector<double>> minor(matrix.size() - 1);
double multiplier = 1.0;
for (size_t i = 0; i < matrix.size(); ++i)
{
for (size_t j = 0; j < minor.size(); ++j)
{
if (j < i)
minor[j] = matrix[j];
else
minor[j] = matrix[j + 1];
}
result += multiplier * matrix[0][i] * sci::determinant(minor);
multiplier *= -1.0;
}
return result;
}
}
其編譯與Visual Studio 2015年正常,但是GCC說
g++ -c -Wall -g -std=c++11 -fPIC -o3 -o build/svector.o svector/svector.cpp
In file included from svector/svector_internal.h:6:0,
from svector/svector.cpp:1:
svector/../include/svector/dep/svector.h: In function 'T sci::determinant(const std::vector<std::vector<T> >&)':
svector/../include/svector/dep/svector.h:2888:28: error: 'minor' was not declared in this scope
for (size_t j = 0; j < minor.size(); ++j)
^
svector/../include/svector/dep/svector.h:2895:60: error: 'minor' was not declared in this scope
result += multiplier * matrix[0][i] * sci::determinant(minor);
^
它看起來對我來說,未成年人絕對在gcc抱怨的範圍內。任何人都可以闡明這個錯誤的原因嗎?
難道你錯過了'#包括'?通常情況下,一些標準庫實現自動包含其他標準頭文件,而不同的實現則不然。如果沒有回答你的問題,請提供[MCVE],以便每個人都可以複製。 –
你將需要發佈你的[MCVE]。我真的厭倦了不得不這樣說。 –