|
-
July 10th, 2005, 02:29 PM
#1
Class templates
I'm having some trouble getting my new, fancy, templated Interpolator class compiling. The problem is that I'm not as comfortable with the template-syntax as I ought to be. Lots of respect and gratitudes to anyone who can help me identify my mistakes.
Code:
class Interpolator
{
Interpolator()
{}
public:
virtual ~Interpolator()
{
}
virtual void Reset() = 0;
virtual void Interpolate(float timespan) = 0;
};
template<typename T>
class InterpolatorImpl : public Interpolator
{
public:
typedef typename T ValueType;
private:
struct Keyframe
{
InterpolatorImpl<T>::ValueType value_;
float time_;
};
typedef std::list<InterpolatorImpl<T>::Keyframe> KeyframeList;
public:
InterpolatorImpl() : currentTime_(0), pTarget_(0)
{
}
virtual ~InterpolatorImpl()
{
}
void SetTarget(ValueType* pTarget)
{
pTarget_ = pTarget;
}
void AddKeyframe(const ValueType& value_, float time);
virtual void Interpolate(float timespan);
virtual void Reset()
{
currentTime_ = 0;
}
private:
float currentTime_;
KeyfameList keyframes_;
ValueType* pTarget_;
};
//Usage
int main()
{
float myFloat = 0;
InterpolatorImpl<float>* myInterp = new InterpolatorImpl<float>();
myInterp->AddKeyframe(24.5f, 2);
myInterp->AddKeyframe(0, 5);
myInterp->SetTarget(&myFloat);
float timespan = 0.05f;
for(float t=0; t<6; t+=timespan)
{
myInterp->Interpolate(timespan);
cout << myFloat << endl;
}
delete myInterp;
}
The compliler complains about "error C2501: 'InterpolatorImpl<T>::Keyframe::value_' : missing storage-class or type specifiers" amongst other things, but that seems to be the root of all the evil...
any ideas?
/Niklas Andersson
Sweden
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|