Thread: how do u access a class protected area?

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    how do u access a class protected area?

    i need to know how to access the class protected area.

    example:

    class functions
    {
    public: //I know how to access the public.

    void call1();

    protected: //this is the area im talking about.

    int var1;
    };

    int main(void)
    {
    functions call;

    call.call1(); //this is how i access public functions.

    return 0;
    }

    thanx 4 the time, CwannaB

  2. #2
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    Code:
    int getVar() const
    {
         return var;
    }
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    In a very basic sense a class looks like this...
    Code:
    class A
    {
       public: // this is the class interface.
    
       private: // this is whats encapsulated.
    
       protected: // This is exactly like private but will be visible in derived classes.
    };
    This means that there is no difference between private and protected until you inherit from this class then inside the derived class the base class private members are not visible but the base class protected members are visible.
    From inside the class you access private and protected members as you do public members but from outside of the class both are inaccessible. Only the interface is visible to the outside world as it should be in any OOP situation.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >i need to know how to access the class protected area.
    The whole purpose of protected is to restrict access to anything except the class itself and any derived classes.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. passing one class to another
    By swappo in forum C++ Programming
    Replies: 2
    Last Post: 04-19-2009, 10:35 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Protected Inheritance
    By golfinguy4 in forum C++ Programming
    Replies: 8
    Last Post: 12-27-2002, 10:56 AM
  5. class access
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-24-2002, 08:00 AM