What is this code doing?

O

oddvark

Hello, under vc7.1 this code compiles:

if (!parent.fillTool)
parent.fillTool.dispose;

where dispose is a method of fillTool.

Notice that dispose does not have ( ) behind it.

Under vc8, this generates an error.

The question is, what is it doing under vc7.1?

Is it actually doing the function call? Or does it think this is just
some function reference and not doing the call?

Thanks.
 
R

red floyd

oddvark said:
Hello, under vc7.1 this code compiles:

if (!parent.fillTool)
parent.fillTool.dispose;

where dispose is a method of fillTool.

Notice that dispose does not have ( ) behind it.

Under vc8, this generates an error.

The question is, what is it doing under vc7.1?

Is it actually doing the function call? Or does it think this is just
some function reference and not doing the call?

My guess is that it's evaluating the rvalue for the address of {whatever
class fillTool is}::dispose, and ignoring it.
 
J

Jim Langston

oddvark said:
Hello, under vc7.1 this code compiles:

if (!parent.fillTool)
parent.fillTool.dispose;

where dispose is a method of fillTool.

Notice that dispose does not have ( ) behind it.

Under vc8, this generates an error.

The question is, what is it doing under vc7.1?

Is it actually doing the function call? Or does it think this is just
some function reference and not doing the call?

Well, a function name is a pointer. And you can do things with pointers.
But in this case, it seems like it's just evaluating the pointer and doing
nothing with it. The same thing as a statement like:

12;

It compiles, but basically does nothing.
 
T

terminator

Well, a function name is a pointer. And you can do things with pointers.
But in this case, it seems like it's just evaluating the pointer and doing
nothing with it. The same thing as a statement like:

12;

It compiles, but basically does nothing.

member function pointer are not combined with object pointers to
esablish a pointer to function in C++.there is nothing such as
delegates in standard C++(in MS C# this would have a meaning).So the
question is still on.why should that line generate an error in a
compiler?.
 
T

terminator

why should that line generate an error in a compiler?. - Hide quoted text -

- Show quoted text -

Sorry.why should that line not generate an error in a compiler?.
 
J

Juha Nieminen

terminator said:
Sorry.why should that line not generate an error in a compiler?.

Because C++ allows rvalues which are not used for anything in
a sentence.
 
P

Pete Becker

Jim said:
Well, a function name is a pointer.

That's almost true for ordinary functions, but not for member functions.
For ordinary funtions, the name of the function decays into a pointer to
the function in most contexts. There is no such rule for member function
names.
And you can do things with pointers.
But in this case, it seems like it's just evaluating the pointer and doing
nothing with it. The same thing as a statement like:

12;

It compiles, but basically does nothing.

That is, in fact, what MS's compilers used to do. But the code is
ill-formed.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
P

Pete Becker

Juha said:
Because C++ allows rvalues which are not used for anything in
a sentence.

But the name of a member function is not an rvalue. The reason it
doesn't generate a diagnostic in MS's older compilers is that those
compilers are wrong.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top