Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Accessing private variables... (http://www.programmingforums.org/showthread.php?t=12904)

n3o_X Mar 29th, 2007 1:00 PM

Accessing private variables...
 
Hello, I am having problems accessing a private variable within my class. I have it setup like this:

:

class MyClass {
private:
        class OtherClass {
        public:
                OtherClass();
                int var1, var2;
        };
        int myVariable;
};


Is it possible for me to set myVariable through the constructor OtherClass()? OtherClass is supposed to set var1 and var2 to -1 and if possible set myVariable.

Oh, and I was also wondering if there was a library function out there to sort an array of strings into alphabetical order.

Any input is greatly appreciated, thanks.

DaWei Mar 29th, 2007 2:11 PM

A nested class does not get special access privileges to the enclosing class.

grumpy Mar 29th, 2007 3:53 PM

The nested class can be declared as a friend if necessary.

However, a design that relies on an nested class accessing private members of a containing class is seriously broken.


All times are GMT -5. The time now is 2:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC