Todo programador de C++ sabe que la librería standard tiene una clase string. Pero, mientras se está aprendiendo, es una buena idea saber cómo poder desarrollar tu propia clase string.
Esa es la razón por la que hice la clase String. No está pensada para proyectos profesionales (para ellos, deberías utilizar la string de la librería standard), sino como una ayuda para aprender C++.
class String
{
char *m_pszString; //Allocated buffer
int m_nAllocated; //Allocated length
public:
//Construction and destruction
String() { /* ... */ }
~String() { /* ... */ }
//Copy constructors
String(const char *pszString) { /* ... */ }
String(const String& rsString) { /* ... */ }
//Operators (assignment)
String& operator=(const char *pszString);
String& operator=(const String& rsString) { /* ... */ }
//Operators (concatenation)
String& operator+=(const char *pszString);
String& operator+=(String& rsString) { /* ... */ }
String operator+(String rsString);
//Operators (comparison)
bool operator<(String sString) { /* ... */ }
bool operator<=(String sString) { /* ... */ }
bool operator>(String sString) { /* ... */ }
bool operator>=(String sString) { /* ... */ }
bool operator==(String sString) { /* ... */ }
bool operator!=(String sString) { /* ... */ }
//Operations
void Clear();
String Lower() { /* ... */ }
String Upper() { /* ... */ }
//Information
int Length() { /* ... */ }
//Cast operators
operator const char*() { /* ... */ }
protected: //Helper functions
/* ... */
};
//Output e input
std::ostream& operator<<(std::ostream& oStream, String& rsString);
std::istream& operator>>(std::istream& iStream, String& rsString);
Seguir leyendo…
Incoming search terms for the article:
Comentarios recientes