CPP/STL/Set/SetCustomClass

From ProgrammingExamples
< CPP‎ | STL/Set
Jump to: navigation, search

SetCustomClass.cpp

#include <iostream>
#include <set>
 
#include "Height.h"
 
int main(int argc, char* argv[])
{
  std::set<Height> S;
 
  for(unsigned int i = 0; i < 10; i++)
  {
    S.insert(Height(i));
  }
 
  return 0;
}

Height.h

#ifndef HEIGHT_H
#define HEIGHT_H
 
class Height
{
  double H;
 
  public:
    Height() {}
    Height(const unsigned int value) {H = value;}
    double getH() const {return H;}
};
 
bool operator< (const Height &H1, const Height &H2)
{
  if(H1.getH() < H2.getH())
  {
    return true;
  }
  else
  {
    return false;
  }
}
 
#endif

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(SetCustomClass)
 
ADD_EXECUTABLE(SetCustomClass SetCustomClass.cpp)