多参数模板类在运行时结束时崩溃 [英] Multi parameters templated class crash at the end of runtime

查看:113
本文介绍了多参数模板类在运行时结束时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include" stdafx.h"

#include< sstream>

#include< iostream>
#include "stdafx.h"
#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆