【问题标题】:Can I add a map as an attribute of a class in C++?我可以在 C++ 中添加地图作为类的属性吗?
【发布时间】:2022-06-15 13:09:00
【问题描述】:

我正在用 C++ 创建一个对 Elden Ring 老板进行评分的程序。我想添加一个地图作为我的父老板类的属性。这是我正在尝试的:

class Boss {
public:
    string name;
    string type;
    int hp;
    bool parriable;
    bool breakPoise;
    string damageTypeDealt;
    map< string, int > absorptions;
    map< string, int > resistances;}

当我尝试创建该类的实例时:

// BOSS OBJECTS
Boss godrickTheGrafted(
    "Godrick the Grafted", 
    "Legend Boss", 
    6080, 
    false, 
    true,
    "Standard Damage, Fire Damage",
    absorptions.insert(pair<string, int>("Phy (Standard)", 0)),
    resistances.insert(pair<string, int>("Not yet", 0))
    );

我在每个地图插入下都收到一条错误消息,提示“未定义标识符”。我目前在我的主要课程之前宣布课程。我什至可以这样做吗?感谢您的帮助。

【问题讨论】:

  • 是的,您可以将map 作为类的数据成员。

标签: c++ class insert attributes maps


猜你喜欢
  • 1970-01-01
  • 2010-10-07
  • 2010-09-12
  • 2017-09-17
  • 1970-01-01
  • 2013-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多