Thread: subclass

  1. #1
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294

    subclass

    Code:
    #ifndef __cDATE_H
    #define __cDATE_H
    
    #include <iostream.h>
    #include <string.h>
    
    class cSTRING 
    {
    	protected:
    		int _nCmpValue, _num1, _num2;
    		char *pszName1, *pszName2;
    	public:
    		cSTRING();
    		
    		cSTRING(char *pname, int returnVal);
    
    		cSTRING(char *pszStr1);
    		cSTRING(cSTRING &rhs);			
    				
    		~cSTRING();
    
    		char *getName1()
    		{
    			return this->pszName1;
    		}
    		
    		char *getName2()
    		{
    			return this->pszName2;
    		}
    
    
    		void print()
    	    {
    		    cout << pszName1 << endl;
    	    }
    
    		cSTRING& operator=(const cSTRING& cStr);
    		cSTRING operator+(const cSTRING& cStr);
    		cSTRING& operator+=(const cSTRING& cStr);
    		int operator==(const cSTRING& cStr);
    		int operator!=(const cSTRING& cStr);
    		cSTRING& Reverse();
    		
    		friend ostream &operator<<(ostream &os, cSTRING& cStr);
    		friend istream &operator>>(istream& is, cSTRING& cStr);
    		int palindrome(const cSTRING& cStr);	
    };
    class cFILENAME:public cSTRING
    {
    	protected:
    		char *pszFName1;
    		char *pszFName2;
    	public:
    		cFILENAME();
    		cFILENAME(char *pszStr1);
    		cFILENAME(cFILENAME &rhs);
    		~cFILENAME();
    	
    	//cFILENAME(cSTRING& s):cSTRING(s){}
    
    	const char* getExtension() const;
    	cFILENAME& toUpper();
    	cFILENAME& toLower();
    
    	char *getFName1()
    	{
    		return this->pszFName1;
    	}
    	char *getFName2()
    	{
    		return this->pszFName2;
    	}
    
    };
    #endif
    i havent done this before, but how would i make a CSTRING of a filename? i am looking @ about.com tutorial, but is very confusing.
    Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more

    The best in Technology and Gaming News

    www.back2games.com

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >class cFILENAMEublic cSTRING
    What good is inheritance here? Containment would be much better as you don't use anything that requires internal knowledge of cSTRING, and a filename is only represented by a string, it isn't a string in and of itself logically:
    Code:
    class cFILENAME
    {
      cSTRING FName;
    public:
      cFILENAME();
      cFILENAME(char *pszStr1)
        : FName(pszStr1)
      {}
      cFILENAME(cSTRING &rhs)
        : FName(rhs)
      {}
      // No destructor needed
    
      const char* getExtension() const;
      cFILENAME& toUpper();
      cFILENAME& toLower();
    
      char *getFName1()
      {
        return FName.getName1();
      }
      char *getFName2()
      {
        return FName.getName2();
      }
    };
    My best code is written with the delete key.

  3. #3
    eat my shorts!
    Join Date
    Apr 2002
    Posts
    294
    lol dont tell me tell te stupid teachers
    Games Reviews Previews Desktop Themes Downloads Paintball Forums Shareware Freeware and much more

    The best in Technology and Gaming News

    www.back2games.com

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >lol dont tell me tell te stupid teachers
    The next time you see your teachers, give them a good hard slap and say it's from Julienne Guth.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with subclass
    By BlackSlash12 in forum C++ Programming
    Replies: 5
    Last Post: 09-02-2007, 10:26 AM
  2. Copying memory, pointers and the like.
    By psychopath in forum C++ Programming
    Replies: 34
    Last Post: 12-12-2006, 01:37 PM
  3. Friend cannot inherit from private subclass
    By MWAAAHAAA in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2006, 04:44 PM
  4. Creating a new object of a subclass problems.
    By Goombaz in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2006, 08:33 AM
  5. Subclass and subtype.
    By Mikro in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2004, 11:28 PM