我正在尝试超载operator <<
,但它总是需要是const
功能。但是,我想更改这个重载函数内的值。我该怎么做呢?
EDIT1:代码存根如下所示:
class Check
{
public:
void operator << (boost::any)
{
// checks weather the given is hresult,string(filename) or int(line no)
// and dump them into the exception object,
// There by hresult will initiate the object and int will throw the object.
// so the input order must be like below
}
private:
Exception exception;
};
Usage
Check check;
check << file->open << __FILE__ << __LINE__ ;
EDIT2:这是为那些曾经说过语法不好实现的人准备的
我不是一个经验丰富的人。程序员。我只是试图为异常制定一个快速解决方案。我的动机是它不应该花费更多时间,它应该很容易打字。因为我的同事都要使用这个异常类。我试图找到解决方案,答案是
1)我的方法
#define INFO __LINE__ << __FILE__
c++
RunAndCheck runAndCheck;
try
{
runAndCheck << checkVersion() << INFO;
runAndCheck << file->Open() << INFO;
runAndCheck << file->rename() << INFO;
}
catch(...)
{
}
2)传统方法
#define INFO __FILE__,__LINE__
try
{
runAndCheck.check(checkVersion(),INFO);
runAndCheck.check(file->Open(),INFO);
runAndCheck.check(file->rename(),INFO);
}
catch(...)
{
}
可能在此存根中它或多或少相同,但请考虑使用 win32API 的情况。必须检查每个调用是否有异常。在这种情况下,我发现