小编Bra*_*ans的帖子

错误:c ++ [map]没有命名类型

我已经将以下内容编写为文本冒险游戏的文本命令解析器的一部分.

我试图将用户输入的字符串与枚举类中的项相关联.以下是我的头文件:

#include <iostream>
#include <map>
#include <string>
using namespace std;

enum class Noun
{
    // Interrogation subjects
    name,                   // ask the subject his name
    base,                   // where is the base?
    attack,                 // when will the attack be?

    invalid
};

map < string, Noun > knownNouns;
knownNouns["name"]      = Noun::name;
knownNouns["base"]      = Noun::base;
knownNouns["attack"]    = Noun::attack;

Noun parseNoun(string &noun)
{
    auto n = knownNouns.find(noun);
    if ( n == knownNouns.end() ) {
        return Noun::invalid;
    }
    return n->second;
Run Code Online (Sandbox Code Playgroud)

当我通过编译器,我得到以下内容:

nouns.h:46:1: error: 'knownNouns' does …
Run Code Online (Sandbox Code Playgroud)

c++ enums parsing map

9
推荐指数
1
解决办法
2万
查看次数

在 RISC-V 中访问硬件性能计数器

我想检测一个程序来访问硬件性能计数器。

我已经编译了一个基本的 Rocketchip ( freechips.rocketchip.system-DefaultConfig) 并riscv-pk用于运行二进制文件。我正在 Verilator 中运行内核的模拟,在 UCB Chipyard 项目中使用大部分默认值编译了它。

二进制文件的 C 如下:

#include <stdio.h>

#define CACHE_MISS      0x100

int loop(int n, int a) {
        int b = 0;
        for(int i=0; i<n; i++) {
                b = a + b;
        }
        return b;
}

int main() {
        int a = 1;
        int n = 200;
        int count = 0;

        printf("Configuring event monitor ...\n");
        /*
        // initialize counters here
        // should start tracking cache misses with 0x100
        __asm__ volatile("csrw …
Run Code Online (Sandbox Code Playgroud)

riscv

5
推荐指数
1
解决办法
832
查看次数

标签 统计

c++ ×1

enums ×1

map ×1

parsing ×1

riscv ×1