How its accessing the private members?

coderzone's Avatar, Join Date: Jul 2004
Team Leader
This does not work as normal
Code:
class test
{
private:
	class privateStruct
	{
	public:
		int m;
		privateStruct(int p){m=p;}
	};
};

void ff()
{
	test::privateStruct ps(4);
	throw ps; //Does not work.. 
}

void main()
{
	try
	{
		ff();
	}
	catch(...)
	{
	}
}
but the code below works
Code:
class test
{
private:
	class privateStruct
	{
	public:
		int m;
		privateStruct(int p){m=p;}
	};
};

void ff()
{
	throw test::privateStruct(4); //Work why
}

void main()
{
	try
	{
		ff();
	}
	catch(...)
	{
	}
}
How??
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Probably a bug in VC compiler. Its creates a Nameless temporary object at

throw test:rivateStruct(4);

Or similar statements like

return test:rivateStruct(4);

and probably VC is not tested for such conditions well enough.