Const

Started by
15 comments, last by OleKaiwalker 20 years, 1 month ago
I''m not 100% sure about this because I don''t use them but I think member function pointers are a relative offset within a class. When you call them you always have to provide an object to call them on like so:
(object.*func_ptr)(10); 

So the value is used to determine which member function to call

- Kaijin
Advertisement
I ran the code in the debugger and it seems that the function pointer gets implicitly converted to a bool, which results in a '1' being written. To see what's going on, try changing the line to:
cout << boolalpha << "ca.count() = " << ca.count << endl; 


The output is:
ca.count() = true  


~nz 

// Website // Google // GameDev // NeHe // MSDN // OpenGL Extensions //

[edited by - neoztar on February 28, 2004 11:41:13 AM]
~neoztar "Any lock can be picked with a big enough hammer"my website | opengl extensions | try here firstguru of the week | msdn library | c++ faq lite
quote:Original post by Polymorphic OOP
No, actually you are wrong. It would be a member function pointer if he did

&a::count

His expression, a.count without parenthesis is completely illegal C++ code and should generate a compiler error. It''s the fault of his compiler.


Ah yes, of course. You are right.

nonpop, I tried compiling your code using gcc and it wouldn''t compile. I guess it must be a bug with the compiler.

- Kaijin
quote:Original post by Kaijin

Ah yes, of course. You are right.

nonpop, I tried compiling your code using gcc and it wouldn''t compile. I guess it must be a bug with the compiler.

- Kaijin


Of course it''s the fault of the compiler, he''s using VC++ 6!
I did a quick test with the sample code w/ borland''s compiler and it complains about the syntax as well.




--{You fight like a dairy farmer!}

--{You fight like a dairy farmer!}

Nice, quite the thread here...

Thx for the answers, even though some of them were a bit off topic
int count () const <-- uhhmm...

_________________Politics is the ability to foretell what is going to happen tomorrow, next week, next month and next year. And to have the ability afterwards to explain why it didn't happen. -- Winston ChurchillGDNet-0.2 - rate users the easy way with this nifty Firefox extension. Updated with new features.
quote:Original post by Drevay
int count () const <-- uhhmm...


WTF?
My stuff.Shameless promotion: FreePop: The GPL god-sim.

This topic is closed to new replies.

Advertisement