|
|
value
(inside class Link
) is a string and the return type of v.get_name()
is also a string. This function returns the string name
inside the class god
. value
inside class Link
. Link(const T& v, Link* p = 0, Link* s = 0
, v
is a const reference to T
and T
is a god
here, but we don't want to change it. We want to copy something from it and paste it into value
(of the class Link
).
|
|
In instantiation of 'Link<T>::Link(const T&, Link<T>*, Link<T>*) [with T = god]': 52:62: required from here 15:89: error: no matching function for call to 'god::get_name() const' 15:89: note: candidate is: 8:9: note: std::string god::get_name() <near match> 8:9: note: no known conversion for implicit 'this' parameter from 'const god*' to 'god*' In instantiation of 'void link_print_all(Link<T>*) [with T = god]': 55:55: required from here 45:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses] |
const
as suggested by the warning, I get this: In instantiation of 'void link_print_all(Link<T>*) [with T = god]': 55:55: required from here 45:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses] |
const
. Arguments can quite often be const
as well.nullptr
instead.Kubani wrote: |
---|
OK, but what does that const in string get_name() const { return name; } mean please? |
p = p -> next()
assignment inside the if
condition?any function that doesn't change the sate of the class should be const |
god_print_all()
and get_name()
are god
's member function and both don't change the state of the class god
. But not making the god_print_all()
const
doesn't cause any problem!get_name()
, although it's called by a const reference (v) but it doesn't change any thing in the state of the class (god
) so logically not making this one, too, const
, should not cause any problem. Don't you agree?
But not making the god_print_all() const doesn't cause any problem! |
Kubani wrote: |
---|
Does that warning mean I had better put parentheses around p = p -> next() assignment inside the if condition? |
|
|
Sure. There's no requirement to make a method const, even if it doesn't change the state of the object. But it's a helpful thing to do. |
god_print_all()
but if we don't make get_name()
const, what part of the class god
will be affected (changed) in v
by value(v.get_name())
?get_name()
const, but I don't know what its reason is. That function does not attempt make a change in const v
.
Kubani wrote: |
---|
Without that change if I run the code using the possibility of the site (that small button), the errors I get are different from yours TheIdeasMan. I don't get that 15:89 error! |
-Wall -Wextra -pedantic
. There are some who make all the warnings errors (-Werror
), and even pedantic warnings (-pedantic-error). This is because one really isn't finished until there are no warnings at all.const
correctness is a huge help too, it can help you to not mess things up.