[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ question...
From: |
Lars Winterfeld |
Subject: |
Re: C++ question... |
Date: |
Wed, 2 Aug 2017 15:49:53 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
Hi,
I think those getter and setter methods are a general concept of object
oriented programming. Maybe some day you will decide that whenever the
name is updated, something else in the class will need updating, too. Or
maybe you later realize that you can trigger a bug when the name is
empty, so you want to enforce a nonzero length. Or maybe - due to some
jit magic - the name is later stored no longer as member but elsewhere,
and you still want to be able to return a reference to the name, etc. So
then, you can just implement that in the getter and setter methods,
instead of browsing through the code again and look at every possible
access of "mname".
(This is general. I haven't looked at the context.)
If this is written in header like in the code snippet, it can easily
optimized away. So it should not cause bad performance.
(If one can be sure that really and forever just data needs to be
stored, use a struct.)
Best wishes,
Lars
Am 02.08.2017 um 12:07 schrieb Julien Bect:
Hi guys,
Still trying to get the JIT back to life, I stumbled upon the following
design :
class
jit_operation
{
public:
// ...
const std::string& name (void) const { return mname; }
void stash_name (const std::string& aname) { mname = aname; }
// ...
private
// ...
std::string mname;
};
Is there some fancy C++ trick hidden there, or would it equivalent to
simply have a public std::string variable "name"?
@++
Julien
- C++ question..., Julien Bect, 2017/08/02
- Re: C++ question...,
Lars Winterfeld <=