I did see that you had those lines commented out. I assumed that you at one point had them uncommented and that was when you were experiencing the issues.
Your Class class uses vec, but it wouldn't have access to the vec defined in the app class without some reference to it (like maybe passing it a pointer to vec when app is instantiated in the app::Begin() method). Creating an instance of class B inside of class A does NOT give class B transparent access to members of class A.
I define vectors and lists inside of classes in my .h files all of the time.
Here is one of the classes that I use vectors in. The first file sets up the types I use all over in my WIP.
ta_types.h:
#ifndef _TA_TYPES_H_
#define _TA_TYPES_H_
/////////////////////////////////////////
// TYPE DEFS ////////////////////////////
/////////////////////////////////////////
// declare some regularly used types
typedef signed int TA_SINT; // 4 byte signed int, redundant, but gives us options
typedef unsigned int TA_UINT; // 4 byte unsigned int
typedef long long TA_SLONG; // 8 byte signed int, we want to make sure that 'long' is 8 bytes
typedef unsigned long long TA_ULONG; // 8 byte unsigned int, we want to make sure that 'long' is 8 bytes
typedef signed short TA_SSHORT; // 2 byte signed int, redundant, but gives us options
typedef unsigned short TA_USHORT; // 2 byte unsigned int
typedef signed char TA_SCHAR; // 1 byte signed int, actually needed if we want negative values for char
typedef unsigned char TA_UCHAR; // 1 byte unsigned int
typedef void (*update_ushort)(TA_USHORT);
typedef void (*void_func)(void);
#endif
index_hash.h (since I can't use std::map, I make a pseudo-hash-like class to handle indices into other lists or vectors):
#ifndef _INDEX_HASH_H_
#define _INDEX_HASH_H_
//
// This class should be using an unordered_map (hash)
// but that is not available in iOS or Android
//
// things we might need
// our predefined types
#include "ta_types.h"
// the std:: classes
#include <string>
#include <vector>
/////////////////////////////////////////
// TYPES ////////////////////////////////
/////////////////////////////////////////
struct tStringIndex
{
std::string id;
TA_USHORT index;
// constructor
tStringIndex(std::string aid,TA_USHORT anindex)
{
id = aid;
index = anindex;
};
};
struct tIntegerIndex
{
TA_UINT id;
TA_USHORT index;
// constructor
tIntegerIndex(TA_UINT aid,TA_USHORT anindex)
{
id = aid;
index = anindex;
};
};
/////////////////////////////////////////
// CONSTANTS ////////////////////////////
/////////////////////////////////////////
#define NO_INDEX_FOUND 65535
/////////////////////////////////////////
// CLASS DEFINITIONS ////////////////////
/////////////////////////////////////////
class StringIndex
{
private:
std::vector<tStringIndex> index_hash;
public:
// constructor
StringIndex() {};
// destructor
~StringIndex() {clear_data();};
public:
// add an index
void add_index(std::string id,TA_USHORT index);
// get the index for the id
TA_USHORT get_index(std::string id);
// clean up
void clear_data();
};
class IntegerIndex
{
private:
std::vector<tIntegerIndex> index_hash;
public:
// constructor
IntegerIndex() {};
// destructor
~IntegerIndex() {clear_data();};
public:
// add an index
void add_index(TA_UINT id,TA_USHORT index);
// get the index for the id
TA_USHORT get_index(TA_UINT id);
// clean up
void clear_data();
};
#endif
index_hash.cpp
#include "index_hash.h"
//
// This class should be using an unordered_map (hash)
// but that is not available in iOS or Android
//
/////////////////////////////////////////
// CLASS IMPLEMENTATIONS ////////////////
/////////////////////////////////////////
void StringIndex::add_index(std::string id,TA_USHORT index)
{
// store it
index_hash.push_back(tStringIndex(id,index));
}
TA_USHORT StringIndex::get_index(std::string id)
{
// local variables
std::vector<tStringIndex>::iterator it1,it2,obj;
// get the ends
it1 = index_hash.begin();
it2 = index_hash.end();
// find the instance
for (obj=it1;obj!=it2;obj++)
{
// check for match
if (obj->id.compare(id) == 0) return obj->index;
}
// bad index
return NO_INDEX_FOUND;
}
void StringIndex::clear_data()
{
// make sure the list is empty
index_hash.clear();
}
void IntegerIndex::add_index(TA_UINT id,TA_USHORT index)
{
// store it
index_hash.push_back(tIntegerIndex(id,index));
}
TA_USHORT IntegerIndex::get_index(TA_UINT id)
{
// local variables
std::vector<tIntegerIndex>::iterator it1,it2,obj;
// get the ends
it1 = index_hash.begin();
it2 = index_hash.end();
// find the instance
for (obj=it1;obj!=it2;obj++)
{
// check for match
if (obj->id == id) return obj->index;
}
// bad index
return NO_INDEX_FOUND;
}
void IntegerIndex::clear_data()
{
// make sure the list is empty
index_hash.clear();
}
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master