c++ - Const twice in one method parameter? -
c++ - Const twice in one method parameter? -
i'm new c++ , trying understand code i'm looking at:
bool classname::classmethod(const struct_thing* const parametername) {}
what purpose of sec "const" in argument? how differ const struct_thing* parametername
?
thanks!
that means const
pointer const
variable.
see next examples:
int x = 5; // non-const int int* y = &x; // non-const pointer non-const int int const = 3; // const int int* const b = &a; // const pointer non-const int int const* const c = &a; // const pointer const int
so can see 2 things have potential mutable, variable , pointer. either of these 2 can const
.
a const
variable works you'd imagine:
int foo = 10; foo += 5; // okay! int const bar = 5; bar += 3; // not okay! should result in compiler warning (at least)
a const
pointer works same way:
int foo = 10; int bar = 5; int* = &foo; = &bar; // okay! int* const b = &foo; b = &bar; // not okay! should result in compiler warning.
c++
Comments
Post a Comment