I have the following code:
class C {
private:
void *data;
public:
constexpr C(nullptr_t) : data(nullptr) { }
C(int i) : data(new int(i)) { }
};
I have created a constructor which takes nullptr_t
, so that I can have code similar to the following:
C foo(2);
// ...
foo = nullptr;
Code similar to this has worked previously on MSVC, however this code fails to compile on GCC 5.3.1 (using -std=c++14
) with on the closing bracket of C(nullptr_t)
with error: function definition does not declare parameters
. Even if i give the parameter a name (in this case _
), I get error: expected ')' before '_'
. This also fails if the constexpr
keyword is removed.
Why am I unable to declare such a constructor, and what are any possible workarounds?