template arguments used within a template function - how? 
Author Message
 template arguments used within a template function - how?

Hi!

Is it possible to get VisualC++6.0 to use template
arguments within a template function (given as an argument
as well) as argument types?

Sorta:

template <class T, void(*foo)(T*)> class Bar {
  T* foobar;

  ..
  void someFunction() {
    ..
    foo(foobar);
    ..
  }

Quote:
}

I can get it to compile just fine, but when instatiating
an instance of a template class, it complains - for
example:

void barbar(int* pInt) {
  ..

Quote:
}

..

Foo<int, barbar> myFoo = new Foo<int,barbar>(..);

- gives an error like:

:test.cpp(46) : error C2440: 'specialization' : cannot
convert from '' to 'void (__cdecl *)( *)'
        None of the functions with this name in scope
match the target type

I can only get template functions to work with void
pointers, which is pretty annoying:

template<class T, void(*foo)(void*)> Foo {

..

Quote:
}

- since that throws the type system right out the window...

What am I doing wrong?

Regards, Gunni Rode



Wed, 20 Apr 2005 19:54:06 GMT  
 template arguments used within a template function - how?
The following compiles fine on my VC6 SP5 installation:

template < class T,
 void (* Func)( T * ) >
class Test
{
public:
 Test()
 {
  T t;
  Func( &t );
 }

Quote:
};

void func_int(int * pi)
{
 *pi = 3;
 std::cout << *pi;

Quote:
}

int main()
{
 Test< int, func_int > test;

 return 0;

Quote:
}

--

Ehsan Akhgari



[WWW: http://www.beginthread.com/Ehsan ]



Thu, 21 Apr 2005 22:56:05 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Template function within Template Class

2. explicit template arguments to function templates

3. Using member function templates in template class under VC++ 5.0

4. friend template class within template class

5. Templates within templates

6. Template methodes within template class

7. Template parameter conflicts with typedef in template argument

8. **Help!** Templates within templates?

9. pointer-to-member-function as template argument ??

10. using templates within an ADT class

11. Default value for template function arguments

12. Using a class as a template argument inside the definition of the class

 

 
Powered by phpBB® Forum Software