![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 29
Rep Power: 0
![]() |
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. Last edited by n3o_X; Mar 29th, 2007 at 12:28 PM. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
A nested class does not get special access privileges to the enclosing class.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,207
Rep Power: 5
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem Associated with Vector Source code | buggytoast | Java | 3 | Apr 2nd, 2006 5:41 AM |
| Any body up for beta testing? | teencoder | C# | 10 | Feb 25th, 2006 8:28 PM |
| Run-time problem | jch02140 | Java | 2 | Aug 9th, 2005 2:34 AM |
| need help beginning c# | dark_omen | C# | 61 | May 4th, 2005 2:57 AM |
| Searching a collection | ellomoto | Java | 1 | Feb 24th, 2005 12:05 AM |