Function Template help

  • Thread starter Alex Rubinsteyn
  • Start date
A

Alex Rubinsteyn

Hi,
I can't figure out why my function templates don't resolve properly.
Anyone here want to help me out?

Code:
---
template <typename T>
Obj* call_method (T* t, void (T::*f)())
{
	(t->*f)();
	return Void;
}

template <typename T, typename Ret>
Obj* call_method (T* t, Ret (T::*f)())
{
	return cpp_to_hyrax((t->*f)());
}
....
I instantiate the template with:
---
T* t = new T;
Obj* o = call_method<T, void> (t, &T::func);
---
T::func's signature is void().
It seems to me that the first template ought to be instantiated, but
it's the second one that wins. Any clues why?

Thanks for any help, 
-Alex
 
A

Alex Rubinsteyn

Also, I tried:
call_method (t, &T::func);
But the compiler tells me that call_method is ambiguous.
 
I

Ian Collins

Alex said:
Hi,
I can't figure out why my function templates don't resolve properly.
Anyone here want to help me out?

Code:
[/QUOTE]

Please post enough to compile.
[QUOTE]
---
template <typename T>
Obj* call_method (T* t, void (T::*f)())
{
	(t->*f)();
	return Void;
}

template <typename T, typename Ret>
Obj* call_method (T* t, Ret (T::*f)())
{
	return cpp_to_hyrax((t->*f)());
}
....
I instantiate the template with:[/QUOTE]

Why not

Obj* o = call_method(t, &T::func);

Which will give you the expected result.
You are explicitly specifying two template types.
 
A

Alex Rubinsteyn

Hi Ian,
Please post enough to compile.
Enough to compile...is a rather lot. I can send you the Visual Studio
project if you're interested.
Why not

Obj* o = call_method(t, &T::func);

Which will give you the expected result.
You are explicitly specifying two template types.

Sorry for the omission, but see my second post. I ended up trying to
specify the template types because call_method(t, &T::func) is (for
some reason) ambiguous. So I guess my question is, how I get the the
first call_method to be instantiated?

Thanks,
Alex
 
A

Alex Rubinsteyn

Whatever the problem was, I've found a way around it by using partially
specialized functor classes instead of a function. Thanks anyways for
the help.

-Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top