Book Image

Microsoft Visual C++ Windows Applications by Example

By : Stefan Bjornander, Stefan Björnander
Book Image

Microsoft Visual C++ Windows Applications by Example

By: Stefan Bjornander, Stefan Björnander

Overview of this book

Table of Contents (15 chapters)
Microsoft Visual C++ Windows Applications by Example
Credits
About the Author
About the Reviewer
Preface
Index

The Set Class


There is no MFC class CSet, so we have to write our own. Similar to List, Set is a sub class to CList. It has a default constructor and a copy constructor, two methods Add and AddAll which add a value or another set, methods Remove and Exists which remove a given element from the set and decide whether a given value is a member of the set.

Set.h

template<typename T>
class Set : public CList<T>
{
  public:
    Set();
    Set(const Set<T>& set);
    Set<T>& operator=(const Set<T>& set);

    void Add(T value);
    void AddAll(Set<T>& set);

    void Remove(T value);
    BOOL Exists(T value) const;

    static Set<T> Merge(Set<T> leftSet, Set<T> rightSet,
                        BOOL bAddEQ, BOOL bAddLT,BOOL bAddGT,
                        BOOL bAddLeft, BOOL bAddRight);

    static Set<T> Union(Set<T> leftSet, Set<T> rightSet);
    static Set<T> Intersection(Set<T> leftSet,
    ...