Thread: inheretance: passing both private and public variables-functions

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    inheretance: passing both private and public variables-functions

    Hi,

    I have one questions.

    How to properly pass both private and public variables/functions from one class to another?


    thank you

    baxy

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    The same way you pass any other objects - as parameters to functions. Do you have a specific example that's causing you trouble? Post some code, and you'll get better help.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    222
    true. I was not specific enough

    Code:
    class A{
    
      publis:
    
      private:
    
      protected:
    
    };
    
    class B:public A:private A : protected A {}  // is this the proper construct if I would like to include all (protected, private and public things form class A)??

    PS

    sorry for waisting time on inadequat, and not properly formated posts

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    My first suggestion would be to try it.

    You'll find that it doesn't compile. A class can only be inherited once. The protection level of the inheritance determines what protection level other code sees. For example, if B inherits A privately, only B will be able to access A's members, when referenced through an object of type B. Derivatives of B will not be able to see them, nor will non-member code. The other protection levels follow in the expected ways.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Private variables lose value between functions
    By SkylerZio in forum C++ Programming
    Replies: 6
    Last Post: 05-15-2010, 11:43 PM
  2. private variables, functions help
    By StealthRT in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2009, 08:56 AM
  3. private/public get/set
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 05-04-2008, 12:49 AM
  4. Replies: 9
    Last Post: 05-03-2007, 03:50 PM
  5. Public vs. Private variables in classes
    By blankstare77 in forum C++ Programming
    Replies: 13
    Last Post: 08-31-2005, 05:43 PM