A
arnuld
this is from C++ Primer 4/e page 260:
there is a class named Sales_item and same_isbn is a member function of
that class.
bool same_isbn(const sales_item &rhs) const {
return isbn == rhs.isbn;
}
author says the word const modifies the type of implicit "this" paramater.
when we will call this:
total.same_isbn(trans)
then the implicit this parameter will be a --const Sales_item*-- that
points to total and it is as if the body of same_isbn is written as:
bool Sales_item::same_isbn (const Sales_item *const this,
const Sales_item &rhs) const
{
return (this->isbn == rhs.isbn);
}
i don't get it, in the paragraph above the author says const modifies the
type of implicit this to --const Sales_item*-- and in the code he says it
is: --const Sales_item *const this-- (notice the 2 consts)
what exactly the type of this is now ?
there is a class named Sales_item and same_isbn is a member function of
that class.
bool same_isbn(const sales_item &rhs) const {
return isbn == rhs.isbn;
}
author says the word const modifies the type of implicit "this" paramater.
when we will call this:
total.same_isbn(trans)
then the implicit this parameter will be a --const Sales_item*-- that
points to total and it is as if the body of same_isbn is written as:
bool Sales_item::same_isbn (const Sales_item *const this,
const Sales_item &rhs) const
{
return (this->isbn == rhs.isbn);
}
i don't get it, in the paragraph above the author says const modifies the
type of implicit this to --const Sales_item*-- and in the code he says it
is: --const Sales_item *const this-- (notice the 2 consts)
what exactly the type of this is now ?