Thread: Newbie question about the Private type in classes

  1. #1
    Registered User
    Join Date
    Aug 2002

    Newbie question about the Private type in classes

    Im really new, and you're all probably laughing by now .
    But, what is the point of the private access type in classes? Is that just there so YOU don't accidentally modify that, and the compiler gives you a kick upside the head if you do? What am I overlooking? Are they really that useless?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    class Object {


    int safest;


    int safe;


    int exposed;


    class NewObject : public Object {


    void manipulate()
    exposed = 12; //..fine...
    safe = 2; //...fine. Derived classes can access "protected:"
    safest = 6; //...cannot do! private to "Object" class...


    int main()

    Object ob;

    ob.safest = 10;// way... = 12;//...nope = 13; // problem

    return 0;

    Ok, so you knew all that, right? Just a refresher. The idea behind it all is "data-hiding". You can use it as a tool to remind yourself that you didn't want to be able to access a member of an objects class directly, (maybe there are butterfly effect implications) or similar reasons. In other realms of programming, this mechanism has helped software library authors control what goes in and out of a class instance, information-wise, providing a sort of controlled-component functionality. But there are many other possible reasons. The point is, unless it's necessary for you at the moment, don't bother. But when you DO need it, you'll be glad it there
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question with accessing private data
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2008, 03:14 AM
  2. Working with winAPI in classes (newbie question)
    By Spyril in forum Windows Programming
    Replies: 3
    Last Post: 11-09-2007, 03:21 PM
  3. Type conversion question.
    By ellis in forum C++ Programming
    Replies: 5
    Last Post: 10-17-2006, 04:05 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM