IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Re: I still don't understand...
First, the function is being declared const, which, as was mentioned above, means that the method promises not to change the underlying object (i.e. the method is constant, the underlying object may or may not be). It has nothing to do with the attributes of the object per se; rather, it has to do with access to the object's attributes via this function.

The virtual keyword is not an issue; it states that derived classes may (or may not; this is not a pure virtual function) override the implementation of IsEmpty(). Nonetheless, the overrides also promise not to change the object.

The statement that"the body of the method is not defined" is wrong, because the function is not declared pure virtual at this level of the class hierarchy. Therefore, there had better be a body for this function, or the compiler will bitch. But lets assume that the function is declared pure virtual, thus:

virtual bool IsEmpty(void) const = 0;

Even then, all you're saying is that you're declaring a function that must be overridden at subsequent levels of the hierarchy, and that everywhere it's overridden, it promises not to change the contents of the object. This, in turn, tells the compiler that it is OK for the compiler to allow invocation of this function on a const object.

Just remember, for functions, const means that the function is not allowed to twiddle the innards of the object.



(And it's not nearly as complex as Todd would have you believe.)





jb4
"So don't pay attention to the approval ratings that say 68% of Americans disapprove of the job this man is doing. I ask you this, does that not also logically mean that 68% approve of the job he's not doing? Think about it. I haven't."
Stephen Colbert, at the White House Correspondent's Dinner 29Apr06
New Which brings up another question.
I've seen the "const = 0" in the design patterns book. What does the " = 0" part imply? I'm assuming that since we are talking C++, this is basically setting the function to null?
New Pure virtual functions
The const is a red herring here. You can have it, or not.

This is implementation detail leaking into the syntax.

If you have an abstract base class and you want to specify required protocol but don't happen to have a sensible default implementation in mind, you define a pure virtual function like this:

[code]
class F
{
public:
virtual void f() = 0;
};
[/code]

which essentially tells the compiler to put a null value into the vtable entry (array of function pointers used for dynamic dispatch) for this particular function at this level of abstraction. It also implies that this class is abstract and may not be instantiated because it is illegal to instance a class with a pure virtual function.




[link|http://www.blackbagops.net|Black Bag Operations Log]

[link|http://www.objectiveclips.com|Artificial Intelligence]

[link|http://www.badpage.info/seaside/html|Scrutinizer]
     C++ question on const - (ChrisR) - (24)
         Don't change the object, I believe - (JayMehaffey) - (2)
             Doh. - (ChrisR) - (1)
                 More than that... - (jb4)
         Re: C++ question on const - (tuberculosis) - (20)
             I still don't understand... - (ChrisR) - (19)
                 Const is not always forced - (JayMehaffey)
                 Its counterintuitive - (tuberculosis) - (14)
                     Say WHAT?!? - (jb4) - (13)
                         You can overload on const - (tuberculosis) - (11)
                             Why the hell would it do / allow that? - (drewk) - (1)
                                 Bell labs has an unlimited crack budget - (tuberculosis)
                             The easiness to keep track of is not the issue - (jb4) - (8)
                                 Huh? - (tuberculosis) - (7)
                                     No... - (jb4) - (6)
                                         I think you're talking past each other... - (admin)
                                         And you specify that by.... - (tuberculosis) - (4)
                                             We'll leave it at that. - (jb4) - (3)
                                                 I wasn't trying to be sarcastic - (tuberculosis) - (2)
                                                     No need to specify OO in this case - (JayMehaffey)
                                                     What does the type of the reference have to do with anything - (jb4)
                         Nominating this for LRPD (new thread) - (lincoln)
                 Re: I still don't understand... - (jb4) - (2)
                     Which brings up another question. - (ChrisR) - (1)
                         Pure virtual functions - (tuberculosis)

This is a lerpadism.
100 ms