473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Pointer to templatized, overloaded member functions

Hi folks! I'm trying to create a function pointer to a templatized,
static, overloaded member function. My class (Mgr) has two functions
with the same name: "go". The first takes a T reference (T is a
template argument), and an int. The second takes a T reference and two
ints.

Here's the code:

=================
#include <iostream>

struct Mgr
{
template<class Tstatic void go(T &, int);

template<class Tstatic void go(T &, int, int);
};

int main()
{
void (Mgr::*foo) (char &, int) = Mgr::go<char>;

return 0;
}
======== EOF =======

Using gcc 3.4.6, I get the following compile error:

test.cpp: In function `int main()':
test.cpp:12: error: no matches converting function `go' to type `void
(struct Mgr::*)(char&, int)'
test.cpp:5: error: candidates are: template<class Tstatic void
Mgr::go(T&, int)
test.cpp:7: error: template<class Tstatic void
Mgr::go(T&, int, int)

Apparently, g++ can't figure out which version of Mgr::go(...) I'm
talking about. Is there any way to disambiguate in this case?

Thanks,
--Steve (sg****@sjm.com)

Jul 2 '07 #1
2 4655
mrstephengross wrote:
Hi folks! I'm trying to create a function pointer to a templatized,
static, overloaded member function. My class (Mgr) has two functions
with the same name: "go". The first takes a T reference (T is a
template argument), and an int. The second takes a T reference and two
ints.

Here's the code:

=================
#include <iostream>

struct Mgr
{
template<class Tstatic void go(T &, int);

template<class Tstatic void go(T &, int, int);
};

int main()
{
void (Mgr::*foo) (char &, int) = Mgr::go<char>;

return 0;
}
======== EOF =======

Using gcc 3.4.6, I get the following compile error:

test.cpp: In function `int main()':
test.cpp:12: error: no matches converting function `go' to type `void
(struct Mgr::*)(char&, int)'
test.cpp:5: error: candidates are: template<class Tstatic void
Mgr::go(T&, int)
test.cpp:7: error: template<class Tstatic void
Mgr::go(T&, int, int)

Apparently, g++ can't figure out which version of Mgr::go(...) I'm
talking about. Is there any way to disambiguate in this case?
There is nothing to disambiguate. You're trying to assign [a pointer
to] a *static* member function to a pointer-to-member variable. Those
are incompatible. You need to make 'foo' a regular pointer-to-function:

void (*foo)(char&, int) = &Mgr::go<char>;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 2 '07 #2
There is nothing to disambiguate. You're trying to assign [a pointer
to] a *static* member function to a pointer-to-member variable. Those
are incompatible. You need to make 'foo' a regular pointer-to-function:

void (*foo)(char&, int) = &Mgr::go<char>;
Aha!

Thanks,
--Steve

Jul 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nitin Bhardwaj | last post by:
Thanx in advance for the response... I wanna enquire ( as it is asked many a times in Interviews that i face as an Engg PostGraduate ) about the overloading capability of the C++ Language. ...
3
by: jimjim | last post by:
Hello, My question concerns as to how a pointer is passed by reference as a function argument. The following is from code taken from the MICO implementation of the CORBA specification. in...
5
by: Ingo Nolden | last post by:
Hi there, I am writing a smart pointer that is similar to the boost intrusive ptr. I am trying to make it behave like a c++ pointer including the implicit and explicit casting behaviour. Below...
5
by: verec | last post by:
I just do not understand this error. Am I misusing dynamic_cast ? What I want to do is to have a single template construct (with no optional argument) so that it works for whatever T I want to...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
6
by: dtschoepe | last post by:
Hi all, Working on homework again... I've got a weird problem, I've been banging my head against the wall on what is causing it. I have a pointer to a typdef named Person. At one point in the...
3
by: Dmitry | last post by:
Hi all, Consider the following code: class A { public: A() {} void DoMethod() { (this->*m_pMethod)(); } protected: virtual void MethodA() { ... }
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
5
by: jknupp | last post by:
In the following program, if the call to bar does not specify the type as <int>, gcc gives the error "no matching function for call to ‘bar(A&, <unresolved overloaded function type>)’". Since bar...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.