K
Kaba
Here is a short snippet of code that does not compile (tested with Vc8
and Comeau). This is because somehow Vector<0> gets instantiated, for
which the array size goes to 0. However, I don't quite get it why it
gets instantiated in the first place. So why does not this compile?
template <int N>
struct Vector
{
int data_[N];
};
template <int HEIGHT, int WIDTH>
struct Matrix
{
};
template <int HEIGHT, int WIDTH>
Vector<WIDTH> operator *(
const Vector<HEIGHT>&,
const Matrix<HEIGHT, WIDTH>&)
{
return Vector<WIDTH>();
}
template <int HEIGHT, int WIDTH>
Vector<WIDTH - 1> operator *(
const Vector<HEIGHT - 1>&,
const Matrix<HEIGHT, WIDTH>&)
{
return Vector<WIDTH - 1>();
}
int main()
{
Matrix<1, 1> transform;
Vector<1> translation;
translation = translation * transform;
return 0;
}
and Comeau). This is because somehow Vector<0> gets instantiated, for
which the array size goes to 0. However, I don't quite get it why it
gets instantiated in the first place. So why does not this compile?
template <int N>
struct Vector
{
int data_[N];
};
template <int HEIGHT, int WIDTH>
struct Matrix
{
};
template <int HEIGHT, int WIDTH>
Vector<WIDTH> operator *(
const Vector<HEIGHT>&,
const Matrix<HEIGHT, WIDTH>&)
{
return Vector<WIDTH>();
}
template <int HEIGHT, int WIDTH>
Vector<WIDTH - 1> operator *(
const Vector<HEIGHT - 1>&,
const Matrix<HEIGHT, WIDTH>&)
{
return Vector<WIDTH - 1>();
}
int main()
{
Matrix<1, 1> transform;
Vector<1> translation;
translation = translation * transform;
return 0;
}