Hi,
I'm new at the forum and at c++ programming.
I have an object vector, but its not storing the objects.
Don't know what to do anymore.
Can someone help me?
teste.cpp
Player.h
Bag.h
Item.h
I'm new at the forum and at c++ programming.
I have an object vector, but its not storing the objects.
Don't know what to do anymore.
Can someone help me?
teste.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <windows.h>
#include "Player.h"
Player character;
int main(){
character.getMochila().addToBag(1);
std::cin.get();
return 0;
}
Player.h
#ifndef _PLAYER_H_
#define _PLAYER_H_
#include "Bag.h"
class Player
{
Bag inventory;
public:
Bag getMochila(){
return this->mochila;
}
};
#endif
Bag.h
#ifndef _BAG_H_
#define _BAG_H_
#include "Item.h"
class Bag
{
std::vector<Item> usable;
public:
void addToBag(int id){
usable.push_back(loadItem(id));
}
Item loadItem(int id){
int i;
std::string name;
int hp,mp;
std::string none;
std::ifstream teste("Itens.gme");
while(std::getline(teste,none,'#')){
i = atoi(none.c_str());
if(i == id){
std::getline(teste,none,'{');
std::getline(teste,name,',');
std::getline(teste,none,',');
hp = atoi(none.c_str());
std::getline(teste,none,',');
mp = atoi(none.c_str());
break;
}
}
teste.close();
Item temp(i,name,hp,mp);
return temp;
}
};
#endif
Item.h
#ifndef _ITEM_H_
#define _ITEM_H_
class Item
{
int id;
std::string name;
int hp;
int mp;
int qnt;
public:
Item(){}
Item(int id, std::string name, int hp, int mp, int qnt = 1){
this->id = id;
this->name = name;
this->hp = hp;
this->mp = mp;
this->qnt = qnt;
}
//-------------------------------GETS-------------------------------------//
int getId(){
this->id;
}
std::string getName(){
this->name;
}
int getHp(){
this->hp;
}
int getMp(){
this->mp;
}
int getQnt(){
this->qnt;
}
//-------------------------------SETS-------------------------------------//
void setQnt(int qnt){
this->qnt = qnt;
}
};
#endif