gpt4 book ai didi

c++ - 如何修复以下 C++ 代码中的 C1202 错误?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:38:52 26 4
gpt4 key购买 nike

<分区>

我正在用 C++ 编写模板四元矩阵并想使用第一行搜索行列式,但它生成了 C1202 错误(C1202 递归类型或函数依赖上下文太复杂)。

不知道我用的是什么编译器,但我是在 windows 上用 VS2017 社区编译的。如果你能告诉我如何检查它就太好了。

#include <iostream>
#include <array>
#include <MatrixNxN.h>

int main()
{
MatrixNxN<float, 4> m1(
{
3, -3, -5, 8,
-3, 2, 4, -6,
2, -5, -7, 5,
-4, 3, 5, -6,
});
auto res = m1.GetDeterminant();
std::system("pause");
}
template<typename _Type, size_t _Size>
_Type MatrixNxN<_Type, _Size>::GetDeterminant()
{
if (_Size == 2)
return operator[](0) * operator[](3) - operator[](2) * operator[](1);

_Type result = 0;
for (size_t i = 0; i < _Size; i++)
{
if (i & 0)
result += operator[](i) * GetMinor(i, 0).GetDeterminant();
else
result -= operator[](i) * GetMinor(i, 0).GetDeterminant();

}
return result;
}

template<typename _Type, size_t _Size>
MatrixNxN<_Type, _Size - 1> MatrixNxN<_Type, _Size>::GetMinor(size_t row, size_t col) const
{
size_t index = 0;
MatrixNxN<_Type, _Size - 1> result;
for (size_t i = 0; i < _Size; i++)
{
if (i == col)
continue;
for (size_t j = 0; j < _Size; j++)
{
if (j == row)
continue;
result[index++] = GetElement(j, i);
}
}
return result;
}

输出日志:

1>       1>------ Build started: Project: Matricies, Configuration: Debug Win32 ------
1>main.cpp
1>d:\projects\matricies\res\headers\matrixnxn.h(9): warning C4200: nonstandard extension used: zero-sized array in struct/union
1>d:\projects\matricies\res\headers\matrixnxn.h(9): note: This member will be ignored by a defaulted constructor or copy/move assignment operator
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to class template instantiation 'MatrixNxN<_Type,0>' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(181): note: while compiling class template member function '_Type MatrixNxN<_Type,1>::GetDeterminant(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation '_Type MatrixNxN<_Type,1>::GetDeterminant(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to class template instantiation 'MatrixNxN<_Type,1>' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(181): note: while compiling class template member function '_Type MatrixNxN<_Type,2>::GetDeterminant(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation '_Type MatrixNxN<_Type,2>::GetDeterminant(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to class template instantiation 'MatrixNxN<_Type,2>' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(181): note: while compiling class template member function '_Type MatrixNxN<_Type,3>::GetDeterminant(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation '_Type MatrixNxN<_Type,3>::GetDeterminant(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to class template instantiation 'MatrixNxN<_Type,3>' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(181): note: while compiling class template member function '_Type MatrixNxN<_Type,4>::GetDeterminant(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\src\main.cpp(14): note: see reference to function template instantiation '_Type MatrixNxN<_Type,4>::GetDeterminant(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\src\main.cpp(13): note: see reference to class template instantiation 'MatrixNxN<float,4>' being compiled
1>d:\projects\matricies\res\headers\matrixnxn.h(9): warning C4307: '*': integral constant overflow
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to class template instantiation 'MatrixNxN<_Type,4294967295>' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(181): note: while compiling class template member function '_Type MatrixNxN<_Type,0>::GetDeterminant(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation '_Type MatrixNxN<_Type,0>::GetDeterminant(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to class template instantiation 'MatrixNxN<_Type,0>' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(181): note: while compiling class template member function '_Type MatrixNxN<_Type,1>::GetDeterminant(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation '_Type MatrixNxN<_Type,1>::GetDeterminant(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(17): warning C4307: '*': integral constant overflow
1>d:\projects\matricies\res\headers\matrixnxn.h(48): warning C4307: '*': integral constant overflow
1>d:\projects\matricies\res\headers\matrixnxn.h(47): note: while compiling class template member function 'MatrixNxN<_Type,4294967295>::MatrixNxN(const MatrixNxN<_Type,4294967295> &)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(213): note: see reference to function template instantiation 'MatrixNxN<_Type,4294967295>::MatrixNxN(const MatrixNxN<_Type,4294967295> &)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(199): note: while compiling class template member function 'MatrixNxN<_Type,4294967295> MatrixNxN<_Type,0>::GetMinor(size_t,size_t) const'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation 'MatrixNxN<_Type,4294967295> MatrixNxN<_Type,0>::GetMinor(size_t,size_t) const' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(199): note: while compiling class template member function 'MatrixNxN<_Type,0> MatrixNxN<_Type,1>::GetMinor(size_t,size_t) const'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation 'MatrixNxN<_Type,0> MatrixNxN<_Type,1>::GetMinor(size_t,size_t) const' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(199): note: while compiling class template member function 'MatrixNxN<_Type,1> MatrixNxN<_Type,2>::GetMinor(size_t,size_t) const'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation 'MatrixNxN<_Type,1> MatrixNxN<_Type,2>::GetMinor(size_t,size_t) const' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(199): note: while compiling class template member function 'MatrixNxN<_Type,2> MatrixNxN<_Type,3>::GetMinor(size_t,size_t) const'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation 'MatrixNxN<_Type,2> MatrixNxN<_Type,3>::GetMinor(size_t,size_t) const' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(199): note: while compiling class template member function 'MatrixNxN<_Type,3> MatrixNxN<_Type,4>::GetMinor(size_t,size_t) const'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(189): note: see reference to function template instantiation 'MatrixNxN<_Type,3> MatrixNxN<_Type,4>::GetMinor(size_t,size_t) const' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(54): note: while compiling class template member function 'MatrixNxN<float,4>::MatrixNxN(std::initializer_list<_Type>)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\src\main.cpp(7): note: see reference to function template instantiation 'MatrixNxN<float,4>::MatrixNxN(std::initializer_list<_Type>)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(41): warning C4307: '*': integral constant overflow
1>d:\projects\matricies\res\headers\matrixnxn.h(40): note: while compiling class template member function 'MatrixNxN<_Type,4294967295>::MatrixNxN(void)'
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\headers\matrixnxn.h(201): note: see reference to function template instantiation 'MatrixNxN<_Type,4294967295>::MatrixNxN(void)' being compiled
1> with
1> [
1> _Type=float
1> ]
1>d:\projects\matricies\res\src\main.cpp(17): fatal error C1202: recursive type or function dependency context too complex
1>MatrixNxN.cpp
1>Generating Code...
1>Done building project "Matricies.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I expected this code will work correct, but something go wrong for now :C

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