ich ein Problem mit auto_ptr in Ausnahmeklassen haben, dass ich schließlich reduziert:Warum kann ich nicht haben eine auto_ptr in einer Ausnahmeklasse
#include <memory>
class MyException
{
std::auto_ptr<int> m_foo2;
};
int main()
{
try
{
throw MyException();
}
catch (const MyException&)
{
}
return 0;
}
Dies irgendwie kompilieren:
/perforce/unstable/test/Common/Exceptions/TestException4.cpp: In function 'int main()': /perforce/unstable/test/Common/Exceptions/TestException4.cpp:12: error: no matching function for call to 'MyException::MyException(MyException)' /perforce/unstable/test/Common/Exceptions/TestException4.cpp:4: note: candidates are: MyException::MyException() /perforce/unstable/test/Common/Exceptions/TestException4.cpp:4: note: MyException::MyException(MyException&) /perforce/unstable/test/Common/Exceptions/TestException4.cpp:12: error: in thrown expression
Und der Fehler verschwindet, wenn ich den auto_ptr entfernen.
Liegt das daran, dass die Ausnahme kopiert oder zugewiesen wird? Gibt es eine Möglichkeit, auto_ptr
s in einer Ausnahme zu verwenden?
Wow, qualitativ hochwertige Antworten hier. Muss eine gute Frage sein. :) – sje397