0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cpp > クラス内での静的定数の宣言 > class MyAPI { public: static const int MAX_NAME_LENGTH; ...

Last updated at Posted at 2015-07-19

引用: C++のためのAPIデザイン by マーティン・レディ
第7章 パフォーマンス

クラス内のこの定数を宣言できる場合は、もっと優れた方法がある。つまり、静的定数として宣言すればよいのだ(オブジェクトごとのメモリ容量に勘定されなくなる)。

myapi.h
class MyAPI
{
public:
    static const int MAX_NAME_LENGTH;
    static const int MAX_RECORDS;
    static const std::string LOG_FILENAME;
};

これで、関連する.cppファイルでこれらの定数用の値を定義できる。

myapi.cpp
const int MyAPI::MAX_NAME_LENGTH = 128;
const int MyAPI::MAX_RECORDS = 65525;
const std::string MyAPI::LOG_FILENAME = "filename.log";
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?