Question

Why can constexpr not apply to constructors?

The following code cannot be compiled with VC++ 2013 CTP.

struct A
{
    constexpr A()
        : _n(5)
    {}

    int _n;
};

constexpr A f()
{
    return A();
}

int main()
{
    auto a = f();
}

error C3757: 'A': type not allowed for 'constexpr' function
Was it helpful?

Solution

VC 2013 does not support all C++11 features yet. Look at MSDN list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top