Thread: Inheritance

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> 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.

  2. #17
    Registered User
    Join Date
    Jul 2007
    Posts
    109
    In the reverse string class how would you guys go about reversing the string?

  3. #18
    Registered User
    Join Date
    Jul 2007
    Posts
    109
    Why would I get this error? I know that my String class is defined:
    error C2504:
    'String' : base class undefined

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    what's in string.h?

  5. #20
    Registered User
    Join Date
    Jul 2007
    Posts
    109
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  4. Inheritance and Polymorphism
    By bench386 in forum C++ Programming
    Replies: 2
    Last Post: 03-18-2004, 10:19 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM