I am working with template meta programming techniques, and I'm just playing around with different methods of doing things at the moment. Here is the code:
template<const int A>
struct iwrapper
{
static const int num = A;
};
template<int A, int B>
constexpr iwrapper<A+B> operator+(iwrapper<A>, iwrapper<B>)
{
return iwrapper<iwrapper<A>::num + iwrapper<B>::num>();
}
int main()
{
constexpr iwrapper<2> first;
constexpr iwrapper<4> second;
constexpr auto answer = first + second;
}
When I try to run this, it gives me this error message:
error: the value of 'first' is not usable in a constant expression
Can someone help me figure out why? Thanks.