Re: function pointers
{ Edits: quoted signature and quoted mod reminder to not quote
signatures, removed. Pplease do not quote signatures. -mod }
In article <1182252118.462229.283700@d30g2000prg.googlegroups.com>,
Mitesh <oopsbabies@hotmail.com> wrote:
On Jun 19, 4:34 pm, Erik Max Francis <m...@alcyone.com> wrote:
ender wrote:
why can't the new operator be used on function pointers?
What would that even mean?
Functions are function not data i.e. they do not encapsulate
(aggregate) data. It is possible to create the data on the heap (if
somehow due to stack size limitation). However function calls have to
as fast as possible (which motivated even the generation of inline
ones). If functions were allocated on the heap we have to pay some
penalty. I understand it this way. Though I am not aware if there is a
technical limitation in creating functions in the heap.
creating a pointer to a function on the heap does not create any
functions. only an 'address of a function'
typedef void (*PF)();
void f();
void foo(std::auto_ptr<PF> arg)
{
if(arg.get())
{
//...
}
}
void test()
{
std::auto_ptr<PF> p(new PF);
*p = &f;
foo(p); // does something
foo(p); // does nothing
}
might be one reason to place the ptr on the heap,
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]