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:
    736
    Likes Received:
    37
    Trophy Points:
    28
    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,336
    Likes Received:
    377
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice