多参数模板类在运行时结束时崩溃 [英] Multi parameters templated class crash at the end of runtime
问题描述
#include< sstream>
#include< iostream>
#include <sstream>
#include<iostream>
推荐答案
在4/27/2018 3:43 PM,Wisnu Wurjantara写道:
On 4/27/2018 3:43 PM, Wisnu Wurjantara wrote:
template< const int WAYS, const int SETS>
class rdmdcache {
private:
bool有效[WAYS] [SETS];
int tag [WAYS] [SETS];
public:
rdmdcache(){
for(int i = 0; i< WAYS; i ++){
for(int j = 0; j< SETS; j ++){
有效[WAYS] [SETS] = false;
tag [WAYS] [SETS] = 0;
template<const int WAYS, const int SETS>
class rdmdcache {
private:
bool valid[WAYS][SETS];
int tag[WAYS][SETS];
public:
rdmdcache() {
for (int i = 0; i < WAYS; i++) {
for (int j = 0; j < SETS; j++) {
valid[WAYS][SETS] = false;
tag[WAYS][SETS] = 0;
通过访问索引越界,这表现出未定义的行为。数组中的有效索引是0到WAYS-1和0到SETS-1。还不清楚为什么要在循环中反复分配相同(无效)元素。
This exhibits undefined behavior, by way of accessing index out of bounds. Valid indexes into your arrays are 0 through WAYS-1 and 0 through SETS-1. It's also unclear why you are assigning to the same (invalid) element over and over in a loop.
这篇关于多参数模板类在运行时结束时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!