inheritance

This is a discussion on inheritance within the C++ Programming forums, part of the General Programming Boards category; Hey everybody, If I declare a non-private static variable in a base class, then a derived class will also have ...

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    inheritance

    Hey everybody,

    If I declare a non-private static variable in a base class, then a derived class will also have the variable right? But will the variable then be static to the derived class(es) or to the base class? (if I change it in a derived class, will it change in the base class too?)
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    yes, if you have a protected or public static all derived base classes can modify it and it represents the exact same memory.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    it represents the exact same memory
    So that means that the base class and all of the derived classes share the variable, and if one class changes it, it changes for the rest of the classes too?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    yeah. that's true. static is little more than glorified globals. It allows only the specified classes free access to them but they are really globals nonetheless

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    ok, thanks a lot!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 04:03 PM
  2. Virtual inheritance
    By 6tr6tr in forum C++ Programming
    Replies: 13
    Last Post: 05-07-2008, 12:20 PM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  4. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 01:46 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21