Skip to content

Instantly share code, notes, and snippets.

@nathan-osman
Created August 19, 2013 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathan-osman/6264792 to your computer and use it in GitHub Desktop.
Save nathan-osman/6264792 to your computer and use it in GitHub Desktop.
Represents a simple class in C++ for storing values of any type.
#include <iostream>
#include "variant.h"
int main(int argc, char * argv[])
{
Variant v;
v.setValue(12);
std::cout << v.getValue<int>() << std::endl;
return 0;
}
all: variant
variant.o: variant.cpp variant.h value.h
g++ -c variant.cpp
main.o: main.cpp variant.h value.h
g++ -c main.cpp
variant: variant.o main.o
g++ variant.o main.o -o variant
#ifndef VALUE_H
#define VALUE_H
class Value
{
};
#endif // VALUE_H
#include "variant.h"
Variant::Variant()
{
}
Variant::~Variant()
{
}
#ifndef VARIANT_H
#define VARIANT_H
#include "value.h"
class Variant
{
public:
Variant();
~Variant();
template <typename T> T getValue() const
{
}
template <typename T> void setValue(const T & value)
{
}
private:
//...
};
#endif // VARIANT_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment