LoginSignup
3
3

More than 5 years have passed since last update.

C++ではファイルスコープ指定にstaticは非推奨

Last updated at Posted at 2017-08-13

変数とか関数をファイルスコープにしたい場合、

C言語

static int g_value;

static void myfunc(int val)
{
 ...
}

のようにグローバル定義の変数名や関数名にstaticを付与します。

C++言語

無名名前空間(namespace {})で囲みます。

namespace {
int g_value;

void myfunc(int val)
{
 ...
}
}

ファイルスコープを目的とした static は、C++では非推奨です。

3
3
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
3
3