Confirming the meaning of the private/protected keywords

This is a discussion on Confirming the meaning of the private/protected keywords within the C++ Programming forums, part of the General Programming Boards category; Hey all, Just had a quick look through the board, and I think it's cleared it up, but I'm not ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    55

    Confirming the meaning of the private/protected keywords

    Hey all,

    Just had a quick look through the board, and I think it's cleared it up, but I'm not 100% certain, so I wanted to ask. When working with classes, does the 'private' keyword mean that any attribute in that section of the class, is only accessible to that class, and not any derived classes? Which would lead onto protected meaning any attributes accessible by the class in which they are declared, and any derived classes.

    However, would a protected attribute be accessible by a base class? For example. Say you have a base class called Circle, and a derived class called Cylinder. Would a protected attribute in Cylinder, be accessible in Circle? I'm guessing no, but I want to clarify.

    Thanks all,

    John.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    "When working with classes, does the 'private' keyword mean that any attribute in that section of the class, is only accessible to that class, and not any derived classes? "

    Private members aren't accessible outside the class, except for friend functions and friend classes.

    "would a protected attribute be accessible by a base class?"

    Usually, you think of whether something in the base class is accessible by the derived class, not the other way around, so I would say no, but I'm not sure. It would take about 5 minutes to test that, so I'll leave that for you to determine.
    Last edited by 7stud; 04-10-2003 at 04:39 PM.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    55
    Thanks dude, that's what I thought. Heh, nice when things go to plan, eh?

    John.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    I was editing my reply when you responded, so you might want to read it again.

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    55
    Ok, thank you again. Sorry, I'm one of those people with Impulse Refresh Disoder. I'll test that later on and see what happens.

    Thanks mate,

    --John

  6. #6
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    From a tutorial:

    Within the class, the keyword protected has the same effect as the keyword private. Data members are still effectively private, in that they can't be accessed by ordinary global functions, but they'll still be accessible to member functions of a derived class.

  7. #7
    Registered User
    Join Date
    Aug 2002
    Posts
    55
    Thanks for the reply Jason. Oh and by the way, impressive resumé mate. Just had a quick look at your site. The 196 Palindrome record was very interesting. Hope all goes well.

    --John.

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    JasonD,

    Have you ever considered a career on Wall Street. Trading systems are becoming more and more like computer games. Speed is everything and systems are getting so complex they need the best programmers, and the pay is stratospheric.

  9. #9
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    7stud, no I have not. But, you are certainly correct. The real-time software required for trading must be very demanding. I am currently in the middle of a fairly large project with a publisher who is already interested in marketing it (in fact, it was his idea, so all systems are go at the moment), so I am not currently looking for a job. I always keep an open mind to new opportunities, however, and that would certainly be interesting.

    Btw, if you are interested in real-time tradings system, you may like to take a look at the Trendax project started by Kim Schmitz.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to color certain keywords?
    By Purity in forum Tech Board
    Replies: 5
    Last Post: 10-20-2005, 02:07 PM
  2. super/interface keywords
    By xErath in forum C++ Programming
    Replies: 4
    Last Post: 06-22-2005, 07:06 PM
  3. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 07:53 PM
  4. new keywords
    By Shadow12345 in forum C++ Programming
    Replies: 8
    Last Post: 07-25-2002, 02:57 AM
  5. Satan
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 81
    Last Post: 12-03-2001, 10:31 PM

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