Template function in template class
Hi,
What is the correct syntax for defining template functions that are declared in a template class?
template<typename T>
class A
{
template<typename C) void foo();
};
template<typename T, C>
void A<T>::foo() {} //doesn't work
EDIT: Got the wrong end of the stick with this one, but interesting none the less.
To call your foo function:
If the function was declared static:
Skizz
To call your foo function:
A <typename> a;a.foo <typename> ();
If the function was declared static:
template <class T>class A{public: template <class S> static void foo (void);};A <typename>::foo <typename> ();
Skizz
It depends on what ur doing, but this should work:
template< class BarType >class Bar{ public: template< class FooType > void Foo( FooType i_Whatever ) { BarElem = static_cast< BarType >( Whatever ); } // This is a specialization of the above method. template<> void Foo( double i_Double ) { BarElem = static_cast< BarType >( Double ); } private: BarType m_BarElem;};void main ( void ){ Bar< int > myBar; // will result in call to general template myBar.Foo( 5.0f ); // will result in call to specialized double template method myBar.Foo( 5.0 ); // force a call to a specific version // will convert 42.0f to integer before calling myBar.Foo< int >( 42.0f );}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement