[comp.lang.c++] initialization of private members

rfg@pink.ACA.MCC.COM (Ron Guilmette) (07/03/89)

Anyone care to tell me if the indicated line is an error or not?

I believe that it should be considered an error whenever you try
to set the value of a private member if the attempt is made from
*outside* a member function of the given class.

What do y'all think?

---------------------------------------------------------------------
// Check that initialization of private data members is illegal
// except via the use of an explicit constructor.

class friendly;

class base {
	int data_member_1;			// private data member
public:
	int data_member_2;
	friend class friendly;			// prevent warnings
	void function_member ();
};

void test ()
{
	base object = { 3, 5 };			// ERROR

	object.function_member ();		// prevent warnings
}
---------------------------------------------------------------------

-- 
// Ron Guilmette  -  MCC  -  Experimental Systems Kit Project
// 3500 West Balcones Center Drive,  Austin, TX  78759  -  (512)338-3740
// ARPA: rfg@mcc.com
// UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg