Вложенные структуры и доступ к данным в C++

Итак, я экспериментирую с созданием простой игры. У меня есть структура с именем Equipment со структурами внутри нее для каждой части, т. е. шлема, тела и т. д. В конструкторе оборудования я создаю объекты подструктур, а в конструкторах подструктур я инициализирую строковые векторы.

Итак, моя проблема заключается в том, что в моей основной функции я создаю объект оборудования, но когда я пытаюсь получить доступ, например, к woodHelm, я получаю ошибку компиляции: «struct Equipment» не имеет члена с именем «helm». Что я делаю неправильно? Или есть другой способ сделать это лучше?

Вот мой Equipment.h (не обращайте внимания на другие подструктуры, я их еще не инициализировал):

#ifndef EQUIP_H
#define EQUIP_H
#include <vector>
#include <string>

using namespace std;

struct Equipment{
    Equipment();
    struct Helmet{
    Helmet(){
        const char* tmp[] = {"Wooden Helmet","1",""};
        vector<string> woodHelm (tmp,tmp+3);
        const char* tmp1[] = {"Iron Helmet","2",""};
        vector<string> ironHelm (tmp1,tmp1+3);
        const char* tmp2[] = {"Steel Helmet","3",""};
        vector<string> steelHelm (tmp2,tmp2+3);
        const char* tmp3[] = {"Riginium Helmet","5","str"};
        vector<string> rigHelm (tmp3,tmp3+3);
    }
    };
    struct Shield{
    Shield(){
        vector<string> woodShield ();
        vector<string> ironShield ();
        vector<string> steelShield ();
        vector<string> rigShield ();
    }
    };
    struct Wep{
    Wep(){
        vector<string> woodSword ();
        vector<string> ironSword ();
        vector<string> steelSword ();
        vector<string> rigSword ();
    }
    };
    struct Body{
    Body(){
        vector<string> woodBody ();
        vector<string> ironBody ();
        vector<string> steelBody ();
        vector<string> rigBody ();
    }
    };
    struct Legs{
    Legs(){
        vector<string> woodLegs ();
        vector<string> ironLegs ();
        vector<string> steelLegs ();
        vector<string> rigLegs ();
    }
    };
    struct Feet{
    Feet(){
        vector<string> leatherBoots ();
        vector<string> ironBoots ();
        vector<string> steelBoots ();
        vector<string> steelToeBoots ();
        vector<string> rigBoots ();
    }
    };
};


#endif

Equipment.cpp:

#include <iostream>
#include "Equipment.h"

using namespace std;

Equipment::Equipment(){
    Helmet helm;
    Shield shield;
    Wep wep;
    Body body;
    Legs legs;
    Feet feet;
}

и main.cpp:

#include <iostream>
#include "Player.h"
#include "Equipment.h"
#include "Items.h"
#include "conio.h"

using namespace std;
using namespace conio;

void init();

int main(int argc, char* argv[]){
    /****INIT****/
    Player p(argv[1],10,1,1);
    Equipment equip;
    Items items;

    cout << clrscr() << gotoRowCol(3,5) << "Player Stats: (" << p.getName() << ")";
    cout << gotoRowCol(4,5) << "HP: " << p.getHP() <<
    gotoRowCol(5,5) << "Att: " << p.getAtt() <<
    gotoRowCol(6,5) << "Def: " << p.getDef();

    //this is where it is messing up
    p.addHelm(equip.helm.woodHelm);


    cout << gotoRowCol(20,1);
}
0
задан Adam Keenan 10 March 2012 в 07:56
поделиться