PRODUCT : Borland C++ NUMBER : 1757 VERSION : 4.0 OS : WIN/DOS DATE : January 7, 1994 PAGE : 1/6 TITLE : Tips on using the BC++ 4.0 Container Class Libraries The container class libraries in Borland C++ 4.0 is entirely template based. That means certain assumptions have been made about the items that are in the container. If these assumptions are not met, you will encounter either an illegal operations compiler error, or the container may not work correctly. For example, when using any of the containers, the item class must have a copy constructor. If it does not have a copy constructor, the program will compile correctly, but when run, it will not work. The following table describes the required operators and member functions for the item class and the container that it applies. -----------------------------------------------------------+ | | | | Constructor | Hash | Container | == | < | = |Default| Copy | Value | ---------------------|----|---|-----|-------|------|-------| TVectorImp | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TCVectorImp | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TSVectorImp | X | X | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TIVectorImp | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| TICVectorImp | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| TISVectorImp | X | X | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TListImp | X | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TSListImp | X | X | | X | X | | ---------------------|----|---|-----|-------|------|-------| TIListImp | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| TISListImp | X | X | | X | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TDoubleListImp | X | | | X | X | | PRODUCT : Borland C++ NUMBER : 1757 VERSION : 4.0 OS : WIN/DOS DATE : January 7, 1994 PAGE : 2/6 TITLE : Tips on using the BC++ 4.0 Container Class Libraries ---------------------|----|---|-----|-------|------|-------| TSDoubleListImp | X | X | | X | X | | ---------------------|----|---|-----|-------|------|-------| TIDoubleListImp | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| TISDoubleListImp | X | X | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TArrayAsVectorImp | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TArray or | | | | | | | TArrayAsVector | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TSArray or | | | | | | | TSArrayAsVector | X | X | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TIArrayAsVector | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| TISArrayAsVector | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TStackAsVectorImp | | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TStack | | | | | | | TStackAsVector | | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TIStackAsVector | | | | | X | | ---------------------|----|---|-----|-------|------|-------| TStackAsListImp | X | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TStackAsList | X | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TIStackAsList | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TDequeAsVectorImp | | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TDeque | | | | | | | TDequeAsVector | | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| PRODUCT : Borland C++ NUMBER : 1757 VERSION : 4.0 OS : WIN/DOS DATE : January 7, 1994 PAGE : 3/6 TITLE : Tips on using the BC++ 4.0 Container Class Libraries TIDequeAsVector | | | | | X | | ---------------------|----|---|-----|-------|------|-------| TDequeAsDoubleListImp| | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TDequeAsDoubleList | | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TIDequeAsDoubleList | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TQueue | | | | | | | TQueueAsVector | | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TIQueueAsVector | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| TQueueAsDoubleList | X | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TIQueueAsDoubleList | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TBagAsVectorImp | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TBag | | | | | | | TBagAsVector | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TIBagAsVector | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TSet | | | | | | | TSetAsVector | X | | X | X | X | | ---------------------|----|---|-----|-------|------|-------| TISetAsVector | X | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| THashTableImp | X | | | X | X | X | ---------------------|----|---|-----|-------|------|-------| TIHashTableImp | X | | | | X | X | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| PRODUCT : Borland C++ NUMBER : 1757 VERSION : 4.0 OS : WIN/DOS DATE : January 7, 1994 PAGE : 4/6 TITLE : Tips on using the BC++ 4.0 Container Class Libraries TDDAssociation (key) | X | | | X | X | X | TDDAssociation (v) | | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TDIAssociation (key) | X | | | X | X | X | TDIAssociation (v) | | | | | X | | ---------------------|----|---|-----|-------|------|-------| TIDAssociation (key) | X | | | | X | X | TIDAssociation (v) | | | | X | X | | ---------------------|----|---|-----|-------|------|-------| TIIAssociation (key) | X | | | | X | X | TIIAssociation (v) | | | | | X | | ---------------------|----|---|-----|-------|------|-------| | | | | | | | ---------------------|----|---|-----|-------|------|-------| TBinarySearchTreeImp | X | X | | | X | | ---------------------|----|---|-----|-------|------|-------| TIBinarySearchTreeImp| X | X | | | X | | ---------------------------------------------------+-------+ While an item class will not need to define every member function and operator, having them defined will make it easier to compare various containers. Here's an example of an item class that defines all of the necessary member functions: class MyClass { protected: string *str; public: // constructors MyClass(); MyClass(const string &s); // copy constructor MyClass(const MyClass &MC); // destructor ~MyClass(); // assignment operator MyClass& operator=(const MyClass &MC); PRODUCT : Borland C++ NUMBER : 1757 VERSION : 4.0 OS : WIN/DOS DATE : January 7, 1994 PAGE : 5/6 TITLE : Tips on using the BC++ 4.0 Container Class Libraries // equality int operator==(const MyClass &MC) const; // comparison for sorted containers int operator<(const MyClass &MC) const; // for hashtables unsigned HashValue() const; }; inline MyClass::MyClass() { str = NULL; cout << "empty MyClass" << endl; } inline MyClass::MyClass(const string &s) { str = new string(s); cout << "Con string " << *str << endl; } inline MyClass::MyClass(const MyClass &MC) { if (MC.str) str = new string(*MC.str); else str = NULL; cout << "Copy string " << *str << endl; } inline MyClass::~MyClass() { if (str) { cout << "Des string " << *str << endl; delete str; } else { cout << "Des empty MyClass" << endl; } } PRODUCT : Borland C++ NUMBER : 1757 VERSION : 4.0 OS : WIN/DOS DATE : January 7, 1994 PAGE : 6/6 TITLE : Tips on using the BC++ 4.0 Container Class Libraries inline MyClass& MyClass::operator=(const MyClass &MC) { if (str != NULL) delete str; if (MC.str) str = new string(*MC.str); else str = NULL; return *this; } inline int MyClass::operator==(const MyClass &MC) const { return (*str == *MC.str); } inline int MyClass::operator<(const MyClass &MC) const { return (*str < *MC.str); } inline unsigned MyClass::HashValue() const { unsigned Hash = 0; if (str == NULL) return 0; for (int i=0; ilength(); i++) Hash += unsigned((*str)[i]); return Hash; } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.