Archived

This topic is now archived and is closed to further replies.

Templates, why can´t I do this?

This topic is 5015 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, Here is part of the class I want to create:

template <class _DataType, class _InterType>
class CnKeyFramePath : public CnPathProducer<_DataType>
{
	//FUNCTIONS

	public:
		//base object style of constructor & destructor

		CnKeyFramePath()						{m_bOk=false;}		
		virtual ~CnKeyFramePath()						{ End(); }	

				
		//a must to call if you want to use the object

		virtual bool Init(std::list< _DataType >& oKeys, _InterType < _DataType >* pInterpolator, float fKeyTime);
the compiler claims about this part: _InterType < _DataType >* pInterpolator in the init call, why can´t I do this?. Thnaks in advance, HexDump.

Share this post


Link to post
Share on other sites
You're meant to do something like this:

template <typename _DataType, template <typename> class _InterType>
class CnKeyFramePath : public CnPathProducer<_DataType>
{
//FUNCTIONS

public:
//base object style of constructor & destructor

CnKeyFramePath() {m_bOk=false;}
virtual ~CnKeyFramePath() { End(); }


//a must to call if you want to use the object

virtual bool Init(std::list< _DataType >& oKeys, _InterType < _DataType >* pInterpolator, float fKeyTime);

If your compiler doesn't support it, you'll have to find a work around or use a better compiler. Edit: can't spell.

[edited by - Null and Void on March 24, 2004 7:01:30 PM]

Share this post


Link to post
Share on other sites
actually, what you want to do IS possible .. if your arguments are right .. the first response is totally incorrect (a template doesn''t KNOW anything, it just tries to compile and if it can with the arguments given, it does).

Here''s a simple example that works


template <typename ContainerType, typename ElementType
class MyClass : ContainerType<ElementType>
{
private:
ElementType prototypeElement;

public:
void SomeFunction(ContainerType<ElementType> &container);
void SomeFunction(MyClass &container);
};


so i don''t know what your error is, but it isn''t the template stuff ... UNLESS _InterType isn''t a templated type.

Share this post


Link to post
Share on other sites
yes, but his operation demands that _InterType be a templated type... therefore, Null and Voids solution is the logical one.

The only extra piece of information is in the template argument list:
template< typename _DataType, template class _InterType >

which is basically specifying that Intertype can be any templated class. Now, upond initialization (when you actually instantiate CnKeyFramePath< T,L >), the compiler will only validate the statement if L is a templated type.

[edited by - psamty10 on March 24, 2004 7:22:02 PM]

Share this post


Link to post
Share on other sites
Will also depend on the compiler your using, not all of them have full template support, i.e. they don''t comply with the spec (VC 6.0 is an example).

Share this post


Link to post
Share on other sites
Well, I´m a bit messed up, I tried your solutions but no one worked for me. I suppose it will be a Vc++ 6.0 prob, that do not support this kind of declarations (it complains that I can´t nest templates).


HexDump

[edited by - HexDump on March 25, 2004 1:40:38 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by HexDump
Well, I´m a bit messed up, I tried your solutions but no one worked for me. I suppose it will be a Vc++ 6.0 prob, that do not support this kind of declarations (it complains that I can´t nest templates).
When you get a compiler error you think may be because of the compiler''s crappiness, try it out in GCC. It''s free after all, and you just need to test this specific part. Get Dev-C++ for ez installation.

Share this post


Link to post
Share on other sites