By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,261 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,261 IT Pros & Developers. It's quick & easy.

Can I write a fn reference?

P: n/a
Is it possible to write: int&(&fn)(int& arg);? Thanks!!!

Dec 12 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Ian
Protoman wrote:
Is it possible to write: int&(&fn)(int& arg);? Thanks!!!

Yes, you just have...
Dec 12 '05 #2

P: n/a
Protoman wrote:
Is it possible to write: int&(&fn)(int& arg);? Thanks!!!


Yes.

V
Dec 12 '05 #3

P: n/a

Protoman wrote:
Is it possible to write: int&(&fn)(int& arg);? Thanks!!!


No its not possible.
References need to be initialized when defined. Your expression ends in
a semicolon which will give non-initialization error.

You can do this -

int& foo(int & x);

int&(&fn)(int& arg) = foo;

This will work.

Dec 12 '05 #4

P: n/a
> No its not possible.
References need to be initialized when defined. Your expression ends in
a semicolon which will give non-initialization error.

You can do this -

int& foo(int & x);

int&(&fn)(int& arg) = foo;

This will work.


The OP might have meant:

struct whatever{

////
int& (&fn)(int& arg);
whatever: fn(some_fn){}
};

Ben
Dec 12 '05 #5

P: n/a

benben wrote:
The OP might have meant:

struct whatever{

////
int& (&fn)(int& arg);
whatever: fn(some_fn){}
};


OK, I missed the context !!

Dec 12 '05 #6

P: n/a
Neelesh Bodas wrote:
benben wrote:
The OP might have meant:

struct whatever{

////
int& (&fn)(int& arg);
whatever: fn(some_fn){}
};

OK, I missed the context !!


No, you didn't. There was no context to miss.
Dec 12 '05 #7

P: n/a

"benben" <be******@yahoo.com.au> wrote in message
news:43***********************@news.optusnet.com.a u...
No its not possible.
References need to be initialized when defined. Your expression ends in
a semicolon which will give non-initialization error.

You can do this -

int& foo(int & x);

int&(&fn)(int& arg) = foo;

This will work.


The OP might have meant:

struct whatever{

////
int& (&fn)(int& arg);
whatever: fn(some_fn){}


Did you mean...

whatever() : fn(some_fn) {}

? (The parentheses are required, aren't they?)

-Howard
Dec 12 '05 #8

P: n/a
I know it is possible, but it seems too weird for me.

I never have seen it in production code.

Is there a reason for doing that?

Do C++ have references to members, too? ;-)

Dec 13 '05 #9

P: n/a
On 2005-12-13, Diego Martins <jo********@gmail.com> wrote:
I know it is possible, but it seems too weird for me.

I never have seen it in production code.

Is there a reason for doing that?
I can't think of one. Since a function can't be an lvalue, what's
the point of having a reference to one?
Do C++ have references to members, too? ;-)


Yep.

--
Neil Cerutti
Dec 13 '05 #10

P: n/a
Neil Cerutti wrote:
On 2005-12-13, Diego Martins <jo********@gmail.com> wrote:
I know it is possible, but it seems too weird for me.

I never have seen it in production code.

Is there a reason for doing that?

I can't think of one. Since a function can't be an lvalue, what's
the point of having a reference to one?

Do C++ have references to members, too? ;-)

Yep.


Really? I just searched the Standard for "reference to member" and it
found one occurrence of that phrase on page 137, in a note (not in the
normative part, but still). The exact sentence is
<<... There is no "reference to member" type in C++. >> (see 8.3.3/3)

V
Dec 13 '05 #11

P: n/a
On 2005-12-13, Victor Bazarov <v.********@comAcast.net> wrote:
Neil Cerutti wrote:
On 2005-12-13, Diego Martins <jo********@gmail.com> wrote:
I know it is possible, but it seems too weird for me.

I never have seen it in production code.

Is there a reason for doing that?

I can't think of one. Since a function can't be an lvalue, what's
the point of having a reference to one?

Do C++ have references to members, too? ;-)

Yep.


Really? I just searched the Standard for "reference to member"
and it found one occurrence of that phrase on page 137, in a
note (not in the normative part, but still). The exact
sentence is
<<... There is no "reference to member" type in C++. >> (see
8.3.3/3)


Well, maybe not. ;-)

Seriously, thanks for the correction. I thinking of references to
objects that happen to be members, which are just references.

--
Neil Cerutti
Dec 13 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.