Possible Duplicate:
const CFoo &bar() const
Which is the meaning of this line?
virtual void Encode (KDataStream & stream) const;
What´s the meaning of const at the end in C++?
Possible Duplicate:
const CFoo &bar() const
Which is the meaning of this line?
virtual void Encode (KDataStream & stream) const;
What´s the meaning of const at the end in C++?
It means -- pass by reference.
The 'const' at the end of the method says that the method implementation will not change the values of any member variables. So, by seeing this in the class interface itself (without having to know the implementation), the clients of the object can know about this behaviour.
Which is the meaning of this line?
virtual void Encode (KDataStream & stream) const;
It's a statement that declares a function.
virtual
means it's a member function that can be overridden by a function of the same name and compatible parameter and return types declared in a class derived from this one. The correct version will be chosen (at run-time, if necessary) according to the type of the object it's invoked on.
void
means it doesn't return anything.
Encode
is the name of the function.
(
marks the start of the parameter list.
KDataStream
is the type of the first parameter.
&
means the parameter is passed by reference.
stream
is the name given to the parameter; it serves as documentation, but can be left out of the declaration without changing the meaning.
)
marks the end of the parameter list.
const
means that it's a member function that can't modify non-static, non-mutable data members of the object it's invoked on. It also allows it to be invoked on objects that are declared const
.
;
marks the end of the statement.
Read up on pointers, if you want to code in c++ you will need to know how these work:
http://www.cplusplus.com/doc/tutorial/pointers/
& means you are passing in the memory address of stream rather the value of stream