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 List Class


List is a sub class of the MFC class CList. It uses the functionality of CList with some improvements. The default constructor does nothing but call the matching constructor of the base class. CList has no copy constructor, so the copy constructor of List adds the given list to its own. Nor does CList have a method Remove which takes a value and removes it from the list if it finds it.

List.h

template<typename T>
class List : public CList<T>
{
  public:
    List();
    List(const List<T>& list);

    void Remove(T value);
    List<T> FilterIf(BOOL Predicate(T value)) const;
    int CountIf(BOOL Predicate(T value)) const;
};

FilterIf takes a function Predicate that returns a logical value as parameter, applies it to every element in the list, and returns a list containing every element that satisfies Predicate (every element in the list for which Predicate returns true). CountIf does the same thing, but returns just the number of satisfied elements...