I working on object that can be used to store any datatype including collections of other datatypes. However, when I try to implement the stack datatype I getting use of undefined type error. I know this means the class is being initialized before it is defined but I don't know how to fix it.
Variable.h
#pragma once
#include "Datatypes.h"
#include "IntegerValue.h"
#include "FloatValue.h"
#include "StringValue.h"
#include "BooleanValue.h"
#include "ListValue.h"
#include "DictionaryValue.h"
#include "StackValue.h"
#include <vector>
class Variable
{
public:
Variable();
Variable(const Variable& src);
~Variable();
Variable(int value, int lockMode = 0);
Variable(double value, int lockMode = 0);
Variable(std::string value, int lockMode = 0);
Variable(const char* value, int lockMode = 0);
Variable(bool value, int lockMode = 0);
long long getInteger() const;
double getFloat() const;
std::string getString() const;
bool getBoolean() const;
bool isNone() const;
void setInteger(long long value);
void setFloat(double value);
void setString(std::string value);
void setBoolean(bool value);
void makeList();
void makeList(Datatypes dt);
void makeDictionarly();
void makeDictionarly(Datatypes dt);
void makeStack();
void makeStack(Datatypes dt);
void makeNone();
// List
void appendListElement(Variable value);
Variable& getListElement(unsigned int index);
Variable getListElementCopy(unsigned int index) const;
void setListElement(unsigned int index, Variable value);
void removeListElement(unsigned int index);
unsigned int getListElementsCount();
void clearListElements();
void fillList(unsigned int targetSize, Variable fillValue);
void pruneList(unsigned int targetSize);
// Dictionarly
bool keyExists(std::string key);
Variable& getDictionarlyElement(std::string key);
void setDictionarlyElement(std::string key, Variable value);
void removeDictionarlyKey(std::string key);
void clearDictionarlyKeys();
// Stack
bool isStackEmpty();
unsigned int stackSize();
void stackPush(Variable value);
Variable stackPop();
Datatypes getDatatype();
void setLockMode(unsigned int mode);
static std::string datatypeName(Datatypes dt);
static Variable createList();
static Variable createList(Datatypes dt, bool locked = false);
static Variable createDictionarly();
static Variable createDictionarly(Datatypes dt, bool locked = false);
static Variable createStack();
static Variable createStack(Datatypes dt, bool locked = false);
void operator=(const Variable& other);
private:
VariableValue* m_value; // Pointer to the value stored in the variable
Datatypes m_datatype; // Datatype of value store in the variable
Datatypes m_elementDatatype; // The datatype the collection elements are locked to if locked
unsigned char m_lockMode; // 0: unlocked 1: type locked 2: value locked
bool m_elementTypeLocked; // If true the elements of the collection are locked to m_elementDatatype
};
StackValue.h
#pragma once
#include "Variable.h"
#include <stack>
class Variable;
class StackValue:public VariableValue
{
public:
StackValue();
StackValue(const StackValue& src);
~StackValue();
void push(Variable value);
Variable pop();
unsigned int size();
bool isEmpty();
private:
std::stack<Variable> m_valueStack; // if this is commented out the error goes away
};
StackValue.cpp
#include "StackValue.h"
StackValue::StackValue()
{
m_valueStack = std::stack<Variable>();
}
StackValue::StackValue(const StackValue& src)
{
m_valueStack = src.m_valueStack;
}
StackValue::~StackValue()
{
}
void StackValue::push(Variable value)
{
//m_valueStack.push(value);
}
Variable StackValue::pop()
{
Variable top = m_valueStack.top();
m_valueStack.pop();
return top;
}
unsigned int StackValue::size()
{
return m_valueStack.size();
}
bool StackValue::isEmpty()
{
return m_valueStack.empty();
}
I tried moving around the includes and forward declarations. They made no difference.