0
0

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 3 years have passed since last update.

enum classを使った際のnamespaceエラー

Last updated at Posted at 2020-09-17

発生コード

enum class GameStates {
  WAIT_START_STATE,
  TRACER_STATE,
};

int nowState = static_cast<int>(GameStates::WAIT_START_STATE); // error

発生した原因

gccコンパイルのオプションに-std=c++03を指定していたため

解決策

  1. gccコンパイルのオプションで-std=c++11-std=gnu++11の指定に変更する
  2. gccのオプションで最小限の驚きには反するがenumで暗黙的にint型にする
enum GameStates {
  WAIT_START_STATE,
  TRACER_STATE,
};

int nowState = WAIT_START_STATE;

今回は開発環境の都合上2.の解決方法を選択した.

参考文献

(1) How to automatically convert strongly typed enum into int?
(2) enum class is not a class or namespace

0
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?