inheritance question

From: Dan Moos (dan.moos_at_verizon.net)
Date: 06/06/04

  • Next message: Robert W Hand: "Re: obj.method(arg) memory"
    Date: Sun, 06 Jun 2004 07:19:53 GMT
    
    

    ok, here goes.

    Say I have a base class:

    class BaseClass {
    public:

    static int SomeVariable;

    };

    next, say I have some derived class

    class Derived : public BaseClass
    {
    };

    by making SomeVariable a static member of the base class, is this a good way
    to provide a sort of global variable to the entire hierarchy without
    breaking encapsulation? I realize some method to insure proper
    initialization of the variable is needed, and that there may be some
    overhead in my constructors in order to test the status of SomeVariable,
    buit is this otherwise a good idea? if not, what is a good alternative?


  • Next message: Robert W Hand: "Re: obj.method(arg) memory"

    Relevant Pages

    • Re: inheritance question
      ... >class BaseClass { ... >static int SomeVariable; ... >by making SomeVariable a static member of the base class, ... You realize that the derived class has no ...
      (alt.comp.lang.learn.c-cpp)
    • Re: C# inheritance broken?
      ... the knowledge that the derived class may still require some ... takes an object of the base class as it's argument. ... derived class instance" is completely unsafe and therefore runs ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Require base class member to be populated by derived classes.
      ... But it's not very different from any of the other half-way solutions that had already been suggested (nor was it clear from your post that your requirement was that the "population" happen during construction). ... In all cases, the general idea is: have some code in the derived class that initializes the members, and have some code in the base class that verifies that initialization. ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Application.Run() problem
      ... still am very much confused about the paint event handler. ... It most obviously should be the derived class, ... It seems that you're not understanding how inheritance works. ... which ensures that the base class uses the same ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Very Confused on Page 33
      ... On page 33 Bruce is explaining inheritance. ... > base class you can also send to objects of the derived class. ... The programmatic difference enables the subclass ...
      (comp.lang.java.help)