Warum läuft das Programm unten auf Mac OSX und Linux ausgeführt, aber nicht auf freebsd?C++ Ausnahme von Konstruktor Core-Dumps auf freebsd, aber nicht auf Linux oder Mac x
Die freebsd Core-Dumps, nachdem die Ausnahme mit der folgenden Meldung ausgelöst wird:
terminate called after throwing an instance of 'ObjectException'
what(): error not allowed
[1] 28946 abort (core dumped) ./bin/main
auf allen drei Plattformen I Gnu Compiler verwenden
freebsd g ++ --version: g ++ (GCC) 4.2.1 20070719
mac os x g ++ --version: i686-apple-darwin10-g ++ - 4.2.1
linux g ++ --version: g ++ (Gentoo 4.3.3 P1.0, torten 10.1.5)
freebsd uname -a: 8.1-RELEASE FreeBSD 8.1-RELEASE
ich Cmake verwenden das Makefile zu erstellen, so dass diese auch ähnlich auf jeder Plattform
Hier ist der Eintrag:
Kopf
#ifndef GUARD_Object_h
#define GUARD_Object_h
#include "boost/scoped_ptr.hpp"
#include "string"
#include "exception"
using std::string;
class Object
{
private:
boost::scoped_ptr<string> _name;
public:
Object(const string&);
string getName();
};
class ObjectException:public std::exception
{
virtual const char* what() const throw()
{
return "error not allowed";
}
};
#endif
Haupt
#include "Object.h"
Object::Object(const string &name):_name (new string)
{
*_name = name;
if(*_name == "error")
{
throw ObjectException();
}
}
string Object::getName()
{
return *_name;
}
Haupt
#include <iostream>
#include "Object.h"
int main()
{
try
{
new Object("error");
} catch(ObjectException&) {
std::cout << "error found" << std::endl;
}
}
Könnten Sie bitte boost :: scoped_ptr in boost :: shared_ptr ändern und es erneut testen? –
shared_ptr gibt das gleiche Ergebnis, – Cyberroadie
auch wenn ich keine Smart Pointer verwende, bekommt es Core Dump – Cyberroadie