#ifndef new_thing_Tutorial_h
#define new_thing_Tutorial_h
#include <vector>
#include "Inventory.h"
usingnamespace std;
class Tutorial
{
public:
Tutorial()
{
Inventory InventAcces;
cout << "I have given you a sword, now lets equip it" << endl;
}
};
#endif
so i know i need to use .push_back or .pop_back, but the program im using dosn't even recognize that inventory is a created vector. what am i doing wrong?
inventory is a local variable in the constructor - it won't exist when the constructor is finished. Make it a member variable, and initialise it in the initialiser list (Google that), provide functions to access it where necessary.
#ifndef new_thing_Tutorial_h
#define new_thing_Tutorial_h
#include <vector> //only include what you need
#include "Inventory.h"
usingnamespace std;class Tutorial
{
public:
Tutorial()
{
// do we actually need this object here
// again it is local and this is the constructor.
// better to have another function - send it a const reference to an
// Inventory object
Inventory InventAcces;
Inventory InventAcces(); // use () to call your constructor
cout << "I have given you a sword, now lets equip it" << endl;
std::cout << "I have given you a sword, now lets equip it\n" ;
}
};
#endif
Try and make the move to having separate .cpp files for each class, rather than inlining every function - name them the same as the class. For example Inventory.cpp The definition of each function including the ctor and dtor go in there.
No worries, look forward to seeing your new code :+)
With the files thing, you can get your IDE to make separate files for you, even make stubs in the .cpp file for your functions that you declare in the header file.
To define an object:
either Inventory InventAcces ; // sane C++
or, if you must: Inventory InventAcces{} ; http://www.stroustrup.com/C++11FAQ.html#uniform-init