By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

Function Template help

P: n/a
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

Nov 4 '06 #1
Share this Question
Share on Google+
4 Replies


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

Nov 4 '06 #2

P: n/a
Alex Rubinsteyn wrote:
Hi,
I can't figure out why my function templates don't resolve properly.
Anyone here want to help me out?

[code]
Please post enough to compile.
---
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);
Why not

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

Which will give you the expected result.
---
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?
You are explicitly specifying two template types.

--
Ian Collins.
Nov 4 '06 #3

P: n/a
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

Nov 4 '06 #4

P: n/a
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

Nov 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.