The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Поиск:  Каталог документации

Next Previous Contents

2. String Class Varieties

There are 3 variety of string classes. Ofcourse, you can build your own string class by simply inheriting from these string classes -

2.1 Multiple Inheritance - Sample Custom String class

You can build your own string class, simply by inheriting the above string classes. You can use multiple inheritance. Download the sample file 'string_multi.h' from string_multi.cpp and the same is reproduced below:


// ******************************************************************
// Sample program to demonstrate constructing your own string class
// by deriving from the String class and stdlib's "string" class
// ******************************************************************

#ifndef __STRING_MULTI_H_
#define __STRING_MULTI_H_

#include <string>
#include "String.h"

// Important Notes: In C++ the constructors, destructors and copy 
//       operator are NOT inherited by the derived classes!!
//       Hence, if the operators like =, + etc.. are defined in
//       base class and those operators use the base class's contructors
//       then you MUST define equivalent constructors in the derived 
//       class. See the sample given below where constructors mystring(), 
//       mystring(char[]) are defined.
//
//       Also when you use operator as in atmpstr + mstr, what you are really
//       calling is atmpstr.operator+(mstr). The atmpstr is declared a mystring

class mystring:public String, string
{
        public:
                mystring():String() {}  // These are needed for operator=, +
                mystring(char bb[]):String(bb) {}  // These are needed for operator=, +
                mystring(char bb[], int start, int slength):String(bb, start, slength) {}
                mystring(int bb):String(bb) {}  // needed by operator+
                mystring(unsigned long bb):String(bb) {}  // needed by operator+
                mystring(long bb):String(bb) {}  // needed by operator+
                mystring(float bb):String(bb) {}  // needed by operator+
                mystring(double bb):String(bb) {}  // needed by operator+
                mystring(const String & rhs):String(rhs) {}  // Copy Constructor needed by operator+
                mystring(StringBuffer sb):String(sb) {}  // Java compatibility
                mystring(int bb, bool dummy):String(bb, dummy) {}  // for StringBuffer class

                int mystraa; // customizations of mystring
        private:
                int mystrbb; // customizations of mystring
};

#endif // __STRING_MULTI_H_


Next Previous Contents


Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2026 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру