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

What is this code doing?

P: n/a
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.

May 31 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
oddvark wrote:
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.
May 31 '07 #2

P: n/a
"oddvark" <dg*****@yahoo.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
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.
Jun 1 '07 #3

P: n/a
On Jun 1, 4:15 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
"oddvark" <dgrd...@yahoo.comwrote in message

news:11**********************@i13g2000prf.googlegr oups.com...
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.
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?.

Jun 1 '07 #4

P: n/a
On Jun 1, 9:19 am, terminator <farid.mehr...@gmail.comwrote:
>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?.

Jun 1 '07 #5

P: n/a
terminator wrote:
On Jun 1, 9:19 am, terminator <farid.mehr...@gmail.comwrote:
>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?.
Because it's a nop.

--
Ian Collins.
Jun 1 '07 #6

P: n/a
terminator wrote:
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.
Jun 1 '07 #7

P: n/a
Jim Langston wrote:
>
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)
Jun 1 '07 #8

P: n/a
Ian Collins wrote:
terminator wrote:
>On Jun 1, 9:19 am, terminator <farid.mehr...@gmail.comwrote:
>>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?.

Because it's a nop.
No, it's illegal.

--

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

P: n/a
Juha Nieminen wrote:
terminator wrote:
>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.
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)
Jun 1 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.