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 ) 2 4693
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<cha r>;
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
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<cha r>;
Aha!
Thanks,
--Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
Why can't the = (assignment) operator be overloaded as a friend
function ?
I work in VS 6.0 ( Win2000 ) as when i referred the MSDN documen'n it
said the following :
|
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 include files:
typedef Context *Context_ptr;
typedef ObjOut<Context> Context_out;
|
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 is the part more or less relevant to my problem.
Version 1 is fine for casting to a derived class, but it must be called
explicitly even though it is used to cast to a base class.
|
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 use it with. Now, if that T happens to be some
subclass of a known base class (object, in this case), I
want to perform some extra stuff ...
I've read Faq#35, and the most natural solution would have
|
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 to functions are hard to
inline for the compiler, and so you won't be able to avoid function
call overhead.
This is an important aspect when you are calling a function very
frequently for evaluation reason: think of the problem of performing...
| |
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 code the pointer changes from storing the memory
location of the Person and contains the value '1'.
I have commented out several pieces of code in order to try to
|
by: Dmitry |
last post by:
Hi all,
Consider the following code:
class A {
public:
A() {}
void DoMethod() { (this->*m_pMethod)(); }
protected:
virtual void MethodA() { ... }
|
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 10 member functions. Can
switch be replaced to member function pointer array?
Please provide me an example of source code to show smart pointer
inside class. Thanks....
|
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
explicitly takes a pointer-to-member with no parameters, why is the
lookup for the overloaded function not able to use the number of
arguments to determine the appropriate function? Is there a relevant
portion of the standard that governs the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |