class A
{
auto getter() const
{
return property;
}
int property = 0;
}
Please notice that getter method is marked as const. Why this
method return "const int"?
If i force it declaring:
int getter() const
it returns "int". It takes me a lot to understand where the is
On Friday, 13 December 2013 at 23:46:14 UTC, Andrea Fontana wrote:
class A
{
auto getter() const
{
return property;
}
int property = 0;
Why this method return "const int"?
Inside getter, "this" is const. Due to transitive const, all the
members through this are const
I read:
Const Member Functions
Const member functions are functions that are not allowed to
change any part of the object through the member function's this
reference.
I'm not changing anything. Just returning it.
Is this a try to avoid something like the following, then?
... B getter() con
Just another thought. If we have:
class B;
struct C;
class A
{
void method() const { ... }
B another_class;
C a_struct;
}
B is just a reference to a object, so method() should not
reassign it. The reference should be const, not the object
itself. method() should be able to call mutab
On Saturday, 14 December 2013 at 00:09:03 UTC, Andrea Fontana
wrote:
I'm not changing anything. Just returning it.
Right, it is just that "auto" keeps the exact type, and in the
const method, the exact type of the members are all const too
since that's how the language enforces that you don't
On Saturday, 14 December 2013 at 00:24:01 UTC, Andrea Fontana
wrote:
Just another thought. If we have:
class B;
struct C;
class A
{
void method() const { ... }
B another_class;
C a_struct;
}
B is just a reference to a object, so method() should not
reassign it. The reference should b
On Friday, 13 December 2013 at 23:46:14 UTC, Andrea Fontana wrote:
class A
{
auto getter() const
{
return property;
}
int property = 0;
}
Please notice that getter method is marked as const. Why this
method return "const int"?
`const` as a function attribute just mar
On Saturday, 14 December 2013 at 00:31:24 UTC, Adam D. Ruppe
wrote:
On Saturday, 14 December 2013 at 00:24:01 UTC, Andrea Fontana
wrote:
Just another thought. If we have:
class B;
struct C;
class A
{
void method() const { ... }
B another_class;
C a_struct;
}
B is just a reference to a o
On Saturday, 14 December 2013 at 00:53:27 UTC, Andrea Fontana
wrote:
Consider this way to escape current constness:
This isn't "escaping" constness. Const only means mutation is
prevented through that particular reference. It is distinct from
immutability.
On 12/13/2013 04:24 PM, Andrea Fontana wrote:
> Just another thought. If we have:
>
> class B;
> struct C;
>
> class A
> {
> void method() const { ... }
> B another_class;
> C a_struct;
> }
>
> B is just a reference to a object, so method() should not reassign it.
> The reference shou
On 12/13/2013 04:30 PM, Adam D. Ruppe wrote:
> There's some discussion that auto might strip off the top level
> const where it is otherwise allowed, but I'm not sure if that's
> actually going to happen or not.
Ah. I was about to respond by "that top level const is silly" but I now
see that it
11 matches
Mail list logo