pointer to template function problem

Hello,

I have a class named Thread in which I have this functions:
1
2
3
4
5
6
7
8
9
10
11
		void Start( void(*workerFunction)() )
		{
			struct Info
			{
				void(*workerFunction)();
			};
			Info* info = new Info;
			info->workerFunction = workerFunction;

			startThread( workerFunction0<Info>, (void*)info ); //This is line 57
		}

1
2
3
4
5
6
		void startThread( void*(*workerFunction)(void*), void* info ) //This is line 135
		{
			if ( pthread_create( &thread, 0, workerFunction, info ) != 0 )
				throw OutOfOtherResourcesError();
		}

1
2
3
4
5
6
7
8
9
		template <typename Info>
		static THREAD_RETURN workerFunction0( void* info )
		{
			Info*& _info = (Info*)info;
			_info->workerFunction();

			delete _info;
			return 0;
		}


Now, the g++ compiler gives me this error:

../../src/threading/thread.h:57: error: no matching function for call to ‘mpi::Thread::startThread(<unresolved overloaded function type>, void*)’
../../src/threading/thread.h:135: note: candidates are: void mpi::Thread::startThread(void* (*)(void*), void*)


And I don't get what the problem is here.

I also have this function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
		template <typename Arg1>
		void Start( void(*workerFunction)(Arg1 arg1), const Arg1& arg1 )
		{
			struct Info
			{
				void(*workerFunction)(Arg1);
				const Arg1* arg1;
			};
			Info* info = new Info;
			info->workerFunction = workerFunction;
			info->arg1 = &arg1;

			startThread( &workerFunction1<Info>, (void*)info );
		}

1
2
3
4
5
6
7
8
9
		template <typename Info>
		static THREAD_RETURN workerFunction1( void* info )
		{
			Info*& _info = (Info*)info;
			_info->workerFunction( *_info->arg1 );

			delete _info;
			return 0;
		}


which doesn't show an error when I build it (it's a static lib), but when I use it with a program, it gives me errors.

Can anyone tell me what the problem is because I have no clue. I don't see why it can't resolve the function like it normally would like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
template <typename Type>
void function()
{
	//Do something with the template like:
	Type* ptr = new Type;
	delete ptr;
}

int main( int argc, char** argv )
{
	void(*functionPointer)() = function<int>;

	return 0;
}
Last edited on
which doesn't show an error when I build it (it's a static lib), but when I use it with a program, it gives me errors.
I happen to be about to use this exact mechanism (getting a pointer to a template function). What error are you getting?
I posted the error I got from g++, basicly what I noticed is that when I fill in the template argument like this:
functionPointerType = function<templateType>;
it can't resolve the function with template argument to the resulting pointer type.
What about &function<templateType>? I got it to work using that.
Doesn't really change anything here. I found the problem though.

For some reason I can't use a class/struct that was defined within the function itself. I moved the Info class out of the function in to the class and now it works.
Topic archived. No new replies allowed.