Thread: Problem with inheritence... I think

  1. #1
    Some Guy
    Join Date
    Jul 2004
    Posts
    32

    Problem with inheritence... I think

    MyString class.h (base class)

    Code:
    #ifndef MYSTRING_H
    #define MYSTRING_H
    
    #include <iostream>
    #include <string>
    #include "LoggableIFC.h"
    
    
    using namespace std;
    
    class MyString:public LoggableIFC
    {
       public:
          MyString();
          MyString(char *);
          ~MyString();
          MyString (const MyString &);
          MyString operator = (const MyString&);
          MyString operator = (const char*);
          bool operator == (const MyString&);
          char& operator [] (int);
          void operator += (const MyString&);
          void operator += (const char*);
          MyString operator + (const MyString&);
          MyString operator + (const char*);
          void getline(istream&);
          int length() const;
          void doubleSize();
          void half();
          ostream &log(ostream &out);
          string toLogFormattedString();
          friend ostream& operator<< (ostream&, MyString&);
      
       private:
          int size;
          int capacity;
          char *data;
       
    };
    
    #endif

    BINARY STRING CLASS.h (CHILD CLASS)

    Code:
    #ifndef Binary_IO_STRING_H
    #define Binary_IO_STRING_H
    
    #include "MyString.h"
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    class Binary_IO_String : public MyString
    {
        private:
            
        public:
            void Read(fstream &) const;
            void Write(fstream &) const;
    
    
    };
    
    #endif
    Tester

    Code:
    #include <iostream>
    #include "MyString.h"
    #include <conio.h>
    #include "binary_io_string.h"
    
    using namespace std;
    
    int main()
    {
    
       
       MyString str("hi");
       char hi[] = "hi";
       Binary_IO_String bs1(hi);    //these two don't work
       Binary_IO_String bs2("hello");  
       Binary_IO_String bs3;
       bs3 = hi;
    
    
    
    
    
       return 0;
    }
    I don't want to put my entire project because it's kind of long. I'll try and summarize.

    Basically, MyString contains various functions for manipulating strings. Binary String is just a derived class and it is supposed to write binary output files, but I'm not that far yet. Basically, it doesn't seem to be inheriting from the base class. Not the constructors or operator overloading. Here are the errors... It appears that it isn't inheriting. Any help is appreciated. Thanks. If you need more code, let me know.

    MyString_Test.cpp: In function `int main()':
    MyString_Test.cpp:30: no matching function for call to `Binary_IO_String::
    Binary_IO_String(char[3])'
    binary_io_string.h:12: candidates are: Binary_IO_String::Binary_IO_String()
    binary_io_string.h:12: Binary_IO_String::Binary_IO_String(const
    Binary_IO_String&)

    MyString_Test.cpp:31: no matching function for call to `Binary_IO_String::
    Binary_IO_String(const char[6])'
    binary_io_string.h:12: candidates are: Binary_IO_String::Binary_IO_String()
    binary_io_string.h:12: Binary_IO_String::Binary_IO_String(const

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Constructors aren't inherited. You need to write matching constructors for Binary_IO_String that call the corresponding constructors in the base class. As it is you only have the default constructor.
    My best code is written with the delete key.

  3. #3
    Some Guy
    Join Date
    Jul 2004
    Posts
    32
    What about the overloaded operators? Are they not inherited? They're not working either.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What about the overloaded operators?
    If it makes sense. Otherwise (such as with assignment) you need to do the same thing as the constructors. Overload the operator for your derived class, and you can use the base class operator in that implementation to tighten up the code.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM