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(...)
{
}
}
Run Code Online (Sandbox Code Playgroud)
但以下代码有效为什么
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(...)
{
}
}
Run Code Online (Sandbox Code Playgroud)
注意:我使用的是 VC++ 6。
我需要回答为什么上面的代码有效。
提前致谢 :)
这是 Visual Studio 6.0 的旧/已知错误。它在构造临时文件时忽略访问说明符。没有可用的修复程序。
将警告级别提高到 3 或更高 (/W3) 将导致违规代码发出警告。