473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can I write a fn reference?

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

Dec 12 '05 #1
11 1451
Ian
Protoman wrote:
Is it possible to write: int&(&fn)(int& arg);? Thanks!!!

Yes, you just have...
Dec 12 '05 #2
Protoman wrote:
Is it possible to write: int&(&fn)(int& arg);? Thanks!!!


Yes.

V
Dec 12 '05 #3

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
> 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

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
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

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Weston C | last post by:
I'm trying to write a generic/reusable form validator in Javascript... just something that checks to make sure required fields have a value. By generic I mean I don't want to explicitly reference...
4
by: m sergei | last post by:
main(int argc, char *argv) the second parameter, argv, to function main takes a pointer to an array. can we also write it in terms of a reference rather than a pointer ? (like &..)
7
by: Scott | last post by:
I need help to modify the code below to pass url variables from a framset. The click to run this will be in the mainFrame. This script works well in a non-frame page. Grabs the current url...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
1
by: news | last post by:
I'm trying to encapsulate a bunch of html widgets such that a containing page can call them to draw themselves in whatever order it chooses as well as easily add new ones. In order to do this...
7
by: Ritu | last post by:
Hi All, Can any body please tell me how i can write a device driver using CSharp. Thanks, Ritu
5
by: Michael | last post by:
Hello, I have a separate Database class that handles any database work that all my asp.net pages can use. My problem is, many times I use try/catch to catch errors, and I want to output these...
7
by: Dr. Zharkov | last post by:
We have program Visual Basic .NET 2003 for construction of 3D-Graphics as a surface z=f (x, y). From VB .NET 2003 we want to transfer coordinates of this surface as myArrayVB (2000, 1) in myArrayVó...
1
by: Ron | last post by:
Hello, I need 2 projects/apps to communicate with each other. I figured out how to create a Class Library project with a form and how to add a new exe project to the solution. I set the...
63
by: Bill Cunningham | last post by:
I don't think I can do this without some help or hints. Here is the code I have. #include <stdio.h> #include <stdlib.h> double input(double input) { int count=0,div=0; double...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.