public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* g++ 3.3.1 (cygwin)
@ 2004-01-20 22:27 Jimen Ching
  0 siblings, 0 replies; only message in thread
From: Jimen Ching @ 2004-01-20 22:27 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-01-20 22:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-20 22:27 g++ 3.3.1 (cygwin) Jimen Ching

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).