Skip to content

Instantly share code, notes, and snippets.

@Spencer-Easton
Created December 7, 2017 19:50
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 Spencer-Easton/f87d5fd6d8e4a353b95722df13e886f5 to your computer and use it in GitHub Desktop.
Save Spencer-Easton/f87d5fd6d8e4a353b95722df13e886f5 to your computer and use it in GitHub Desktop.
#include "vertex.h"
#include "graph.h"
#include "set.h"
using namespace std;
class base
{
public:
base()
{
index = i++;
}
~base() = default;
virtual string print() const
{
return "Base " + to_string(index);
}
friend std::ostream &operator<<(std::ostream &out, const base &rhs);
bool operator==(const base &rhs) const
{
return index == rhs.index;
}
bool operator<(const base &rhs) const
{
return index < rhs.index;
}
protected:
static int i;
int index;
};
int base::i = 0;
class derived : public base
{
public:
derived() : base()
{
}
string print() const override
{
return "Derived " + to_string(index);
}
};
void printClass(const custom::set<base> &s1)
{
for (auto it = s1.begin(); it != s1.end(); it++)
{
std::cout << *it << " " << endl;
}
}
inline std::ostream &operator<<(std::ostream &out, const base &rhs)
{
out << rhs.print();
return out;
}
int main()
{
custom::set<base> s1;
derived d;
base b;
//s1.insert(b);
s1.insert(d);
printClass(s1);
//Base 0
//Base 1
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment