Skip to content

Instantly share code, notes, and snippets.

@gin0606
Created July 16, 2014 10:31
Show Gist options
  • Select an option

  • Save gin0606/b88b7f3b5f34a0ec8fb6 to your computer and use it in GitHub Desktop.

Select an option

Save gin0606/b88b7f3b5f34a0ec8fb6 to your computer and use it in GitHub Desktop.
// Hoge::FugaEnumを前方宣言したい
class Hoge : public TemplateClass<Hoge, FugaEnum> {
public:
enum class FugaEnum {
FOO,
}
}
@uwnm
Copy link

uwnm commented Jul 17, 2014

なんと、C++11ならenumを前方宣言できます!

struct Hoge { // Hoge must be complete.
  enum FugaEnum : int;  // forward declaration
};

enum Hoge::FugaEnum : int { // definition
  FOO
};

int foo() {
  Hoge::FugaEnum x = Hoge::FugaEnum::FOO;
  return x;
}

が、内部列挙型FugaEnumを前方宣言するには外部クラスHogeを完全に定義しなければいけないので、CRTPを適用することは(テンプレートとプリプロセッサの神様が物凄くトリッキーなことを考え付かなければ)できないのではないでしょうか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment