Is it possible to store a pointer to a template function whose template
type is not known until runtime?
eg,
Can I store a pointer to this?
template<class T> f() {...}
I know how to store pointers to ordinary functions, but not template
functions.
Thanks,
Suzanne 5 7351
"Suzanne Vogel" <su************ *@hotmail.com> wrote in message
news:40******** @news.unc.edu.. . Is it possible to store a pointer to a template function whose
template type is not known until runtime?
eg, Can I store a pointer to this?
template<class T> f() {...}
Unfortunately, no. You can store pointers to specializations of
template functions, but not the actual template. If you give an
example of your intended use, perhaps we can suggest another way to
accomplish the same thing. I know how to store pointers to ordinary functions, but not template functions.
They're stored just like other function pointer. You have to be
careful about getting the address of the correct overload.
Jonathan
"Suzanne Vogel" <su************ *@hotmail.com> wrote in message news:40******** @news.unc.edu.. . Is it possible to store a pointer to a template function whose template type is not known until runtime?
eg, Can I store a pointer to this?
template<class T> f() {...}
No. Templates are instantiated at build time.
You can only get pointers to specific specializations .
Ron Natalie wrote: "Suzanne Vogel" <su************ *@hotmail.com> wrote in message news:40******** @news.unc.edu.. .
Is it possible to store a pointer to a template function whose template type is not known until runtime?
eg, Can I store a pointer to this?
template<clas s T> f() {...}
No. Templates are instantiated at build time. You can only get pointers to specific specializations .
Except in this case, the function signature is independant of the
template argument. (and the syntax is incorrect too - but that's a
different issue)
This works:
(assuming the template function returns an int)
int (* ptr_fooFunc)() = &f<x>;
"Gianni Mariani" <gi*******@mari ani.ws> wrote in message news:bu******** @dispatch.conce ntric.net... Except in this case, the function signature is independant of the template argument. (and the syntax is incorrect too - but that's a different issue)
It's still the case. There's no requirement that the function signature reflect the template
args. (Except for bugs in certain compilers like VC++ 6). It just means you have to
provide the explicit template argument list. This works: (assuming the template function returns an int)
int (* ptr_fooFunc)() = &f<x>;
Doesn't solve the problem the original poster asked for. They wanted to bind the function
by pointer later to a specific specialization. This binds it to the f<x> specialization at initialization
time.
Ron Natalie wrote: "Gianni Mariani" <gi*******@mari ani.ws> wrote in message news:bu******** @dispatch.conce ntric.net...
This works: (assuming the template function returns an int)
int (* ptr_fooFunc)() = &f<x>;
Doesn't solve the problem the original poster asked for. They wanted to bind the function by pointer later to a specific specialization. This binds it to the f<x> specialization at initialization time.
Correct: doesn't solve the problem. Thanks, Ron. And thanks Gianni, for
the suggestion.
Suzanne This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roland Bengtsson |
last post by:
I have a class Conception and I have this in a vector, it should be:
vector<Conception> vek; // vector
vector<Conception>::iterator vek; // iterator to vek
But what if I want to have pointers to class Conception instead? How
can I do that? And how should I write to declare an iterator to this
vector?
|
by: Carsten Spieß |
last post by:
Hello all,
i have a problem with a template constructor
I reduced my code to the following (compiled with gcc 2.7.2) to show
my problem:
// a base class
class Base{};
// two derived classes
|
by: Manuel |
last post by:
Hi.
Before all, please excuse me for bad english and for very newbie
questions. I hope to don't boring you.
I'm trying to write a very simple GUI using openGL.
So I'm writing some different widgets classes, like buttons, images,
slider, etc...
Each class has a draw() method.
|
by: Nindi73 |
last post by:
A few days a ago I posted my code for a deep copy pointer which
doesn't require the pointee object to have a virtual copy constructor.
I need help with checking that it was exception safe and exception
neutral/
I got a reply from Bux with his code for a smart pointer with far fewer
lines of code
and more cleaner design, not over engineered like mine.
...
|
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: weaknessforcats |
last post by:
Handle Classes
Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the implementation so the two can vary independently.
Handle classes usually contain a pointer to the object implementation. The Handle object is used rather than the implemented object. This leaves the implemented object free to change without affecting...
|
by: .rhavin grobert |
last post by:
guess you have the following:
_________________________________________________
template <class T>
class CQVector
{
public:
// find an element, returns index or -1 if none is found
int find(int id) const;
private:
|
by: Juha Nieminen |
last post by:
I asked a long time ago in this group how to make a smart pointer
which works with incomplete types. I got this answer (only relevant
parts included):
//------------------------------------------------------------------
template<typename Data_t>
class SmartPointer
{
Data_t* data;
void(*deleterFunc)(Data_t*);
|
by: ghulands |
last post by:
I am having trouble implementing some function pointer stuff in c++
An object can register itself for many events
void addEventListener(CFObject *target, CFEventHandler callback,
uint8_t event);
so I declared a function pointer like
typedef void (CFObject::*CFEventHandler)(CFEvent *theEvent);
|
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: 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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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...
| |