Recursive templates: compilation error under g++
Posted
by
Johannes
on Stack Overflow
See other posts from Stack Overflow
or by Johannes
Published on 2011-03-14T15:59:09Z
Indexed on
2011/03/14
16:10 UTC
Read the original article
Hit count: 234
Hi,
I am trying to use templates recursively to define (at compile-time) a d-tuple of doubles. The code below compiles fine with Visual Studio 2010, but g++ fails and complains that it "cannot call constructor 'point<1>::point' directly".
Could anyone please shed some light on what is going on here?
Many thanks, Jo
#include <iostream>
#include <utility>
using namespace std;
template <const int N>
class point
{
private:
pair<double, point<N-1> > coordPointPair;
public:
point()
{
coordPointPair.first = 0;
coordPointPair.second.point<N-1>::point();
}
};
template<>
class point<1>
{
private:
double coord;
public:
point()
{
coord= 0;
}
};
int main()
{
point<5> myPoint;
return 0;
}
© Stack Overflow or respective owner