P
Pavel Shved
Hello.
Some languages contain so-called 'properties' - class members that
behave in different ways depending on whether you read or modify them.
I wonder whether is can be declared like this:
class A{
...
int& Prop()
{
//When we write to some kind of field
m_modified = true; //Lets assume for example, that we need to
know
//whether we use property for writing.
return m_field;
};
const int& Prop() const
{
//When we read something from field
return m_field;
};
};
Will the non-constant function be invoked only when the value returned
is being modified?
Some languages contain so-called 'properties' - class members that
behave in different ways depending on whether you read or modify them.
I wonder whether is can be declared like this:
class A{
...
int& Prop()
{
//When we write to some kind of field
m_modified = true; //Lets assume for example, that we need to
know
//whether we use property for writing.
return m_field;
};
const int& Prop() const
{
//When we read something from field
return m_field;
};
};
Will the non-constant function be invoked only when the value returned
is being modified?