tags:

views:

73

answers:

3
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 Following Code Works Why

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(...)
    {
    }
}

NOTE : I am using VC++ 6.

I need answer why the above code works.

Thanks in Advance :)

A: 

Even the second code snippet won't compile. privateStruct cannot be accessed in the function ff().

Sameer
+1  A: 

The code in your second example works because Visual C++ 6 is notorious for its horrible standards compliance.

It works by accident.

Shmoopty
+4  A: 

This is an old/known bug with Visual Studio 6.0. It ignores access specifiers when constructing temporaries. No fix is available.

Raising the warning level to 3 or higher (/W3) will cause the offending code to give a warning.

dauphic