CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    7

    inheritance or include ?

    Hello,
    Im facing a conception problem in my program. I have a statics library (all methods are static, no data member) and I would like to use these methods but I would like to know if I should inherit from this class or an simple include will do ?
    I have to use the static library in different class, Ive been told to inherit virtually to have one instance of the library used.

    Could you guys give me your opinion ?

    Thank you for help

  2. #2
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: inheritance or include ?

    If your "library" has only static methods, what does it mean to have an "instance" of that class?

    As far as I know, just include your class, and use it.

    You can publicly inherit from it if you want to expand the class to give it more methods, but when it comes down to using it, just include and call it.

  3. #3
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: inheritance or include ?

    Quote Originally Posted by sw21
    I have a statics library (all methods are static, no data member)
    You could consider turning it into a namespace of free functions instead.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #4
    Join Date
    Sep 2009
    Posts
    7

    Re: inheritance or include ?

    Quote Originally Posted by monarch_dodra View Post
    If your "library" has only static methods, what does it mean to have an "instance" of that class?

    As far as I know, just include your class, and use it.

    You can publicly inherit from it if you want to expand the class to give it more methods, but when it comes down to using it, just include and call it.
    That is what I think as well. How to be sure it is better ? is there any book where this case is covered, with a typical excample ? it is for a professional use, I have to be sure of what I do.
    Thank you anyway for your answers

  5. #5
    Join Date
    Dec 2009
    Posts
    145

    Re: inheritance or include ?

    Quote Originally Posted by sw21 View Post
    That is what I think as well. How to be sure it is better ? is there any book where this case is covered, with a typical excample ? it is for a professional use, I have to be sure of what I do.
    Thank you anyway for your answers
    "Static" or dynamic aside
    If you don't include a header file then you won't be able to use it!
    Anyone claiming that he can should be crackers.
    Also, calling static methods crops up different issues

  6. #6
    Join Date
    Jul 2009
    Posts
    37

    Re: inheritance or include ?

    Nice explanation, but is it a free library ? You mind if I ask for sharing ?
    Sig-na-tju-(r)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured