【问题标题】:Expected Initializer before '<' token'<' 标记之前的预期初始化程序
【发布时间】:2014-09-03 16:25:33
【问题描述】:

我正在使用以下标头定义。

finstrumentor.hpp

#ifndef _FINSTRUMENTOR_HPP_
#define _FINSTRUMENTOR_HPP_

#include "../../../api/probe_API.hpp"
#include <cstdint>

extern Instrumentor* INSTRUMENTOR_INSTANCE;

typedef void (*instrumentation_func)(uint16_t);

class Probe_Info {

  public :
    uint8_t* patch_addr;
    uint8_t size;
};

class Statistics {

  public:
    uint64_t addr;
    uint64_t count;

};

class Finstrumentor : public Instrumentor {

  protected :
    void (*prolog_func)(uint16_t);
    void (*epilog_func)(uint16_t);

  public :
    Finstrumentor(instrumentation_func prolog_func, instrumentation_func epilog_
    void initialize(Instrumentor* inst);
    virtual ~Finstrumentor();

};

/* Global Data */
typedef std::unordered_map<int, std::list<Probe_Info*>*> probe_map;
extern probe_map probe_info;

typedef std::map<uint64_t, uint16_t> func_table;
extern func_table functions;

extern uint16_t func_id_counter;

Statistics* global_stats;


#endif /* _FINSTRUMENTOR_HPP_ */

当我包含此文件时,我在编译期间收到以下错误。

In file included from ../src/instrumentor.cpp:4:
../src/finstrumentor.hpp: At global scope:
../src/finstrumentor.hpp:43: error: expected initializer before ‘<’ token
../src/finstrumentor.hpp:44: error: ‘probe_map’ does not name a type
../src/finstrumentor.hpp:46: error: expected initializer before ‘<’ token
../src/finstrumentor.hpp:47: error: ‘func_table’ does not name a type
../src/cyg_functions.cpp:16: error: ‘probe_map’ does not name a type
../src/cyg_functions.cpp:17: error: ‘func_table’ does not name a type

【问题讨论】:

  • 考虑将其分解为MCVE,例如:你确定你包括吗?
  • 是的。我应该。刚刚发现 unordered_map 是一个缺失的包含修复它。谢谢你的提醒:)。

标签: c++ stl g++


【解决方案1】:

您尚未包含定义 listmapunordered_map 的标头。

#include <list>
#include <map>
#include <unordered_map>

另外,你不应该像_FINSTRUMENTOR_HPP_ 那样使用reserved names。您应该(至少)从开头删除下划线。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多