3

According to this, you can forward declare an enum. But what happens if the class or struct that the enum was declared in wasn't defined? What's the recourse then?

I've also gone through this thread and it doesn't answer this question.

Example:

File A1.h

struct A1 {
  enum E1 { x1, y1, z1 };
  void fn1(A1::E1& e);
  void fn1(A2::E2& e);
};

File A2.h

struct A2 {
  enum E2 { x2, y2, z2 };
  void fn2(A1::E1& e);
  void fn2(A2::E2& e);
};
Community
  • 1
  • 1
Adrian
  • 10,246
  • 4
  • 44
  • 110
  • You mean, analogous to [forward-declaring nested classes](http://stackoverflow.com/q/951234/420683)? – dyp Apr 30 '14 at 20:31
  • Gah! Yes. This still hasn't been fixed!? :( – Adrian Apr 30 '14 at 20:54
  • As far as I know, no. Maybe there's an alternative solution to your problem? Could you provide an example? – dyp Apr 30 '14 at 21:09
  • Unless something is used only by the class, put it outside the class to prevent issues such as this. You can put the class and and associated supporting definitions in a namespace. – Neil Kirk Apr 30 '14 at 22:07
  • @NeilKirk It is actually used inside. I didn't show that. Updated example to reflect that. – Adrian Apr 30 '14 at 22:09
  • 3
    @Adrian, I think you misunderstand Neil Kirk, he said unless something is only used by the class. Meaning if you use it elsewhere, you probably should put it outside of the class. You can assign it to an appropriate namespace though. – OmnipotentEntity Apr 30 '14 at 22:12
  • @OmnipotentEntity, I see. I guess that's an answer. Thanks. – Adrian Apr 30 '14 at 22:14
  • Possible duplicate of [Forward declaration of nested enum](http://stackoverflow.com/questions/2238170/forward-declaration-of-nested-enum) – Ciro Santilli OurBigBook.com Dec 18 '16 at 11:29

0 Answers0