Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. class Colour
  2. {
  3. public:
  4. static const Colour Red;
  5. static const Colour Green;
  6. static const Colour Blue;
  7.  
  8. Colour(){}
  9.  
  10. bool operator==(const Colour &other) const{
  11. if(other.colourCode == this->colourCode){return true;}else{return false;}
  12. }
  13.  
  14. Colour & operator=(const Colour & other){
  15. this->colourCode = other.colourCode;
  16. }
  17.  
  18. Colour(const Colour & other){
  19. *this = other;}
  20.  
  21. private:
  22. int colourCode;
  23.  
  24. Colour(int colourCodeIn){
  25. colourCode = colourCodeIn;
  26. }
  27. };
  28.  
  29. const Colour Colour::Red(1);
  30. const Colour Colour::Green(2);
  31. const Colour Colour::Blue(3);
  32.  
  33. class Pen
  34. {
  35. public:
  36. Pen(){}
  37. void setColour(const Colour & infarbe){
  38. farbe = infarbe;
  39. }
  40. Colour farbe;
  41. };
  42.  
  43. int main()
  44. {
  45. Pen myPen1;
  46.  
  47. myPen1.setColour(Colour::Blue);
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement