L
Leon
I'm having a bit of a template-problem, and I was wondering if you
guru's know what I'm doing wrong here...
I want to create a Vertex class that supports a toPoint() method. Now,
in my case there are 2 ways of calculating toPoint(), and I want to be
able to choose (at compile time) this method in a flexible way.
Therefore, I want to template this Vertex class.
For example, when I create a Vertex<fixed_tag> I want the 'fixed'
toPoint()-method to be used, whereas when I create a
Vertex<interval_tag>, it should use the 'interval' variant.
What I've done so far is this:
//--------------------------
struct fixed_tag{};
struct interval_tag{};
template<class S>
class Vertex{
//
//Member-vars, constructor e.d.
//
template<fixed_tag>
Point toPoint() const;
template<interval_tag>
Point toPoint() const;
};
//Implementation
template<fixed_tag>
Point Vertex::toPoint() const{
//Calculate and return fixed point
}
template<interval_tag>
Point Vertex::toPoint() const{
//Calculate and return interval point
}
//---------------------------
Needless to say, the above code doesn't compile properly (VS.NET), and
I've tried quite a few variants on this, but I just can't seem to get
it *right*...
Who can tell me what I'm doing wrong here?
Thanks.
guru's know what I'm doing wrong here...
I want to create a Vertex class that supports a toPoint() method. Now,
in my case there are 2 ways of calculating toPoint(), and I want to be
able to choose (at compile time) this method in a flexible way.
Therefore, I want to template this Vertex class.
For example, when I create a Vertex<fixed_tag> I want the 'fixed'
toPoint()-method to be used, whereas when I create a
Vertex<interval_tag>, it should use the 'interval' variant.
What I've done so far is this:
//--------------------------
struct fixed_tag{};
struct interval_tag{};
template<class S>
class Vertex{
//
//Member-vars, constructor e.d.
//
template<fixed_tag>
Point toPoint() const;
template<interval_tag>
Point toPoint() const;
};
//Implementation
template<fixed_tag>
Point Vertex::toPoint() const{
//Calculate and return fixed point
}
template<interval_tag>
Point Vertex::toPoint() const{
//Calculate and return interval point
}
//---------------------------
Needless to say, the above code doesn't compile properly (VS.NET), and
I've tried quite a few variants on this, but I just can't seem to get
it *right*...
Who can tell me what I'm doing wrong here?
Thanks.