-
>> In this case, the constructors are needed, and you must pass the value to the base constructor to initialize it
Assuming plain copying is desired, the compiler supplied copy constructor will do that for you. The other constructors are needed for that reason.
-
In the reverse string class how would you guys go about reversing the string?
-
Why would I get this error? I know that my String class is defined:
error C2504:
'String' : base class undefined
-
-
Here is the code for reversestring.h and string.h:
Code:
//reverse.h
#ifndef ReverseString_H
#define ReverseString_H
#include <iostream>
#include "strdrv.h"
#include "string.h"
using namespace std;
class ReverseString: public String
{
public:
ReverseString();
ReverseString(const ReverseString &rhs);
ReverseString(const char *str);
ReverseString operator=(const ReverseString &rhs);
ReverseString operator~();
};
#endif
//string.h
#ifndef String_H
#define String_H
#include <iostream>
#include "strdrv.h"
using namespace std;
static char* blank = '\0';
class String
{
friend String operator+(const String& lhs, const String& rhs);
friend String operator+(const String& rhs, const char* str);
friend String operator+(const char* str, const String& rhs);
friend String operator+(const String& rhs, char str);
friend String operator+(char str, const String& rhs);
friend int operator==(const String& lhs, const String& rhs);
friend int operator!=(const String& lhs, const String& rhs);
friend int operator< (const String& lhs, const String& rhs);
friend int operator<=(const String& lhs, const String& rhs);
friend int operator> (const String& lhs, const String& rhs);
friend int operator>=(const String& lhs, const String& rhs);
friend char* operator+(const String &rhs, int element);
friend char* operator+(int element, const String &rhs);
friend ostream& operator<<(ostream&, const String&);
public:
String();
String(const char* str);
String(char nme);
String(int sizeofstring);
String(const String &rhs);
String(char letter, int repeat);
~String();
void setName(const char* aname);
String& operator= (const String &rhs);
String& operator= (const char *st);
String& operator= (const char st);
String& operator+=(const String & str);
String operator+() const;
char& operator[](int i);
char& operator[](int i) const;
String& operator++();
String& operator--();
String operator++(int x);
String operator--(int x);
int getLength()const;
String substr(int start, int length);
const char* c_str() const;
void print();
protected:
int stringlength;
int size;
char * name;
char *buf;
};
#endif