1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How its accessing the private members?

Discussion in 'C' started by coderzone, Jul 27, 2005.

  1. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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??
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Probably a bug in VC compiler. Its creates a Nameless temporary object at

    throw test::privateStruct(4);

    Or similar statements like

    return test::privateStruct(4);

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

Share This Page