Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 29th, 2007, 12:00 PM   #1
n3o_X
Newbie
 
Join Date: Jan 2005
Posts: 29
Rep Power: 0 n3o_X is on a distinguished road
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.
n3o_X is offline   Reply With Quote
Old Mar 29th, 2007, 1:11 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Mar 29th, 2007, 2:53 PM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,207
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:20 AM.

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