gpt4 book ai didi

c++ - 第一个归因的段错误(C++ 中的类)

转载 作者:行者123 更新时间:2023-11-28 02:35:45 25 4
gpt4 key购买 nike

我有这段代码,但我在第一次尝试进行归因时一直遇到段错误

#include <iostream>

using namespace std;

template <class type, int linha, int coluna>
class MetodoNw{

private:
type metodoNw[linha][coluna];
int match, missmatch, gap;

public:
MetodoNw();
};

template <class type, int linha, int coluna>
MetodoNw <type,linha,coluna> :: MetodoNw(){
match = 5;
missmatch = -3;
gap = -4;
}

int main(){
cout << "######" << endl;
MetodoNw<int,2000,2000> metodo1;
return 0;
}

如果我声明一些像 int i; 这样的变量,它会很好地工作。如果我有类似 int i=0; 的东西,那么我会得到一个段错误。与 cout、printf 等函数相同。我只是不知道该怎么做...试过教程、书籍、gdb,但一无所获。
注意:这只是一段代码,这就是它什么都不做的原因。

最佳答案

段错误可能是由于大小为 2000x2000 的大数组造成的

我建议使用 std::vector像下面这样:

std::vector< std::vector<type> > metodoNw ;

并像这样初始化它:

template <class type, int linha, int coluna>
MetodoNw <type,linha,coluna> :: MetodoNw():
metodoNw(linha, std::vector<type>(coluna)){
match = 5;
missmatch = -3;
gap = -4;

}

关于c++ - 第一个归因的段错误(C++ 中的类),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27532828/

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