-
Notifications
You must be signed in to change notification settings - Fork 341
C plus plus
Johan Wikman edited this page Apr 19, 2017
·
17 revisions
From 2.2 onwards MaxScale will be built as C++. That does not mean that MaxScale will be rewritten in C++ but that C++ can be used were appropriate.
The corollary of that is that the reserving of some resources can fail, then it cannot be done in the constructor. In practice that means that if the creation of an object may fail, then there must be a separate create
-function that reserves the resources and once reserved, creates the object or returns NULL if the creation fails.
class Heavy
{
public:
static Heavy* create(...)
{
Heavy* pThis = NULL;
auto_ptr<Resource>*sResource(...);
if (sResource.get())
{
pThis = new Heavy(sResource);
}
return pThis;
}
private:
Heavy(auto_ptr<Resource> sResource)
: m_sResource(sResource)
{
}
};
Note that although MaxScale code itself must not throw exceptions, the runtime-library may do so (e.g. new
if the allocation fails).
Even though MaxScale code itself must not throw exceptions, new C++ code should be exception safe. That is,