I am creating a tuple of vectors of various objects – and it is a singleton. I have nested this singleton class within another class.
Right now I have no idea what the issue is, but I am unable to revise and set values to member variables of the objects in the vectors of that singleton tuple (that is a mouthful!). Basically, I think I am struggling with the syntax, and it is due to my lack of experience. I have searched for someone else doing this, but unable to grasp what might be taking place.
The crux of the issue is with size_t addDevice(); below:
#include <string>
#include <vector>
#include <tuple>
#define TOTAL 100
typedef std::tuple<
std::vector<X>,
std::vector<Y>,
std::vector<Z>
> SingletonTuple;
class Device
{
public:
Device() { activeStatus = false; };
private:
bool activeStatus;
};
class Controller
{
public:
Controller() { };
size_t addDevice();
class Singleton
{
public:
static Singleton& Instance()
{
static Singleton singleton(TOTAL);
return singleton;
}
private:
friend class Controller;
size_t numDevices;
SingletoneTuple singletonTuple;
Singleton(size_t total);
};
};
Controller::Singleton::Singleton(size_t total)
{
numDevices = total;
Singleton::singleton = std::make_tuple(std::vector<X>(total), std::vector<Y>(total), std::vector<Z>(total));
}
size_t Controller::addDevice()
{
index = computeIndex(); //defined elsewhere but assume it returns an index
std::get<std::vector<X>>(singleton)[index].activeStatus = true;
std::get<std::vector<Y>>(singleton)[index].activeStatus = true;
std::get<std::vector<Z>>(singleton)[index].activeStatus = true;
return index;
}
These from above show up as an invalid function regarding std::get:
std::get<std::vector<X>>(singleton)[index].activeStatus = true;
std::get<std::vector<Y>>(singleton)[index].activeStatus = true;
std::get<std::vector<Z>>(singleton)[index].activeStatus = true;
Does anybody know how I should revise the syntax of the above 3 items in regards to having a nested singleton and trying to reference member variables inside objects inside vectors inside a singleton tuple?
I have searched for solutions but it seems nobody is trying this particular approach.
1