Author Topic: C++ and class definition Q  (Read 3259 times)

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1317
  • Karma: +26/-0
    • View Profile
C++ and class definition Q
« on: October 04, 2021, 03:33:46 am »
So this may be somewhat basic to those of you who have spent some time developing in C++, but to me where it's been years that I've written anything in C++ and being only familiar with the basic class declaraion I'm not sure how to interpret this:

Code: [Select]
   class _IMPORT fstream : public fstreambase, public iostream {
   public:
                           fstream() ;

                           fstream(const char* name,
                                           int mode,
                                           int prot=filebuf::openprot) ;
                           fstream(int fd) ;
                           fstream(int fd, char*  p, int l) ;
                           ~fstream() ;
           filebuf*        rdbuf() { return fstreambase::rdbuf(); }
           void            open(const char* name, int mode,
                                   int prot=filebuf::openprot) ;
   } ;

So is the above declaring fstream as the class? If so, what exactly does the "public fstreambace, public iostream" mean?

I think fstream is the class since I see the multiple class constructor declarations under the "public:..." section.

Thanks!

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: C++ and class definition Q
« Reply #1 on: October 04, 2021, 09:15:54 am »
fstream is the class which inherits all methods and member variables from classes fstreambase and iostream. Therefore, it's multiple inheritance (inherits from more than one class).

When it says _IMPORT, I suspect that this header is to be included by users of the class (and not or not only the implementer of the class) and that the class implementation is contained in a DLL.

I am unsure about the use of "public" for the classes inherited from. Maybe you can further restrict access to methods and member variables ( in case another class inherits from fstream). So, if a method of iostream is public and you inherit the class as protected, then maybe this method becomes protected for a class that inherits from fstream. I'd need to check that with a C++ book.
« Last Edit: October 04, 2021, 09:27:35 am by Lars »

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1317
  • Karma: +26/-0
    • View Profile
Re: C++ and class definition Q
« Reply #2 on: October 04, 2021, 04:21:50 pm »
Thanks Lars, I understand that explanation.

Yeah, this is part of a header file in the IBMCPP. Similarly to the OS2_DevToolkit, I am going through the IBMCPP install and picking up the appropriate class names to toss into my VSE Modern Theme package.

I wanted to make sure that what I thought was a class, was in fact a class.