This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

g++ 3.3.1 (cygwin)


Hi,

Is the following code legal C++?  Because I didn't get any errors, and I'm
expecting to get an error when I access me->test in struct2::func(), since
it's private.  Did the standard allow this and I've overlooked it?

class struct1
	{
public:
	struct1(int i) : s2(this) { test = i; }
	void func(int i) { s2.func(i); }

private:
	int test;
	struct struct2
		{
		struct1 *me;
		struct2(struct1 *s) { me = s; }
		void func(int i) { me->test = i; }
		};
	struct2 s2;
	};

int
main()
	{
	struct1 s1(1);
	s1.func(2);
	return 0;
	}

--jc
-- 
Jimen Ching (WH6BRR)      jching@flex.com     wh6brr@uhm.ampr.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]