0

If the nested struct will contain only static constant members, will it affect performance anyhow? I want to use it to scope these constants.

class File {

    public:

        struct Mode {
            static const int Read = 0x01, Write = 0x02, Append = 0x04;
        };

};

Is this a good practice?

HemoGoblin
  • 155
  • 4
  • 1
    Forget about performance and concentrate on writing good quality, robust, readable code. – Paul R May 02 '12 at 09:34
  • 1
    Avoiding certain kinds of performance hit is a property of "good quality" code (see "Shlemiel the painter", although also see responses to "Shlemiel" that mention "premature optimization"). This isn't one of those performance problems, but you're quite right to want to know the consequences of using a construct you've never used before. "Forgetting about" performance is a luxury of those with enough experience that they can easily identify the rare cases where they're going to have to remember it in a hurry, and use their intelligence plus a profiler to work out why their code is low-quality. – Steve Jessop May 02 '12 at 10:02

1 Answers1

3

Not at all, the variables are resolved at compile-time, not run-time.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • Corrollary: if in doubt, read the generated code to see what the "usage site" looks like for these constants. – unwind May 02 '12 at 09:30