Re: int (*&)()
Asif Zaidi wrote:
On Feb 8, 12:28 am, Syron <mr.sy...@googlemail.com> wrote:
Am 08.02.2010 04:45, schrieb Asif Zaidi:
What does the syntax in subject line mean - how should I read it.
Thanks
Asif
if this is a typedef (like 'int(*&func)()') it is a reference to a
pointer to a function that returns an int.
Kind regards, Syron
I am trying to implement the following and getting compile failure.
Any suggestions ?
typedef int (*& func_ptr1)();
int goo()
{
cout << "un goo" << endl;
return 0;
}
int main()
{
func_ptr1 p1 = goo;
}
The error is below
1>d:\profiles\waz003\my documents\visual studio 2008\projects
\hw5_3\hw5_3\hw5_3.cpp(174) : error C2440: 'initializing' : cannot
convert from 'int (__cdecl *)(void)' to 'func_ptr1'
I believe the reference to non-const requires a modifiable l-value for
initialisation. Your 'goo' is not an lvalue. You can either do
typedef int (* const & func_ptr_ref)();
...
func_ptr_ref pr = goo;
or define a variable of the type 'pointer to function' and initialise
your reference with it:
...
int main()
{
int (*some_fptr)();
func_ptr1 p1 = some_fptr;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask