K
Ken Camann
I was a bit surprised to find that my compiler (MSVC++) actually
accepts the following as legal. It cleans up the code very nicely,
but I am sort of confused about some of the finer points of how the
naming and template systems interact in a compiler. Does the
following always work?
In Vector3.h, I have this class
namespace Geometry {
termplate<typename NumericType>
class Vector3
{
....
};
}
In another file, Triangle.h, I have
#include <Vector3.h>
namespace Geometry {
template<typename NumericType>
class Triangle
{
public:
typedef Vector3<NumericType> Vector3;
//Then I go on to use Vector3 instead of Vector3<NumericType>
};
}
Like I said, I was pretty surprised it let me take the "root" part of
the template name Vector3<NumericType> and redefine it as a specific
type, namely the specific type that inherits the template type from
the class that it belongs to. Needless to say, if I type in
Vector3<NumericType> after the typedef this produces an error, since
the symbol Vector3 = Vector3<NumericType> already.
Thanks for your time,
Ken
accepts the following as legal. It cleans up the code very nicely,
but I am sort of confused about some of the finer points of how the
naming and template systems interact in a compiler. Does the
following always work?
In Vector3.h, I have this class
namespace Geometry {
termplate<typename NumericType>
class Vector3
{
....
};
}
In another file, Triangle.h, I have
#include <Vector3.h>
namespace Geometry {
template<typename NumericType>
class Triangle
{
public:
typedef Vector3<NumericType> Vector3;
//Then I go on to use Vector3 instead of Vector3<NumericType>
};
}
Like I said, I was pretty surprised it let me take the "root" part of
the template name Vector3<NumericType> and redefine it as a specific
type, namely the specific type that inherits the template type from
the class that it belongs to. Needless to say, if I type in
Vector3<NumericType> after the typedef this produces an error, since
the symbol Vector3 = Vector3<NumericType> already.
Thanks for your time,
Ken