Here is a simple class Test :
#pragma once
class Test
{
public:
constexpr Test() : i(0) {}
constexpr Test(int i) : i(i) {}
private:
int i;
};
and I when I execute this main :
#include <iostream>
#include "Test.h"
int main()
{
constexpr Test t(2);
std::cin.get();
}
everything compiles perfectly. But when I move the implementation of both constructors of Test to a source file Test.cpp like so :
#include "Test.h"
constexpr Test::Test() : i(0)
{
}
constexpr Test::Test(int i) : i(i)
{
}
I've got this following error message :
Error C2127 't': illegal initialization of 'constexpr' entity with a non-constant expression
What's wrong here? (I am using Visual Studio 2015)