0

I have a header file (A):

namespace CChristianLifeMinistryDefines
{
    using S_DISCUSSION_HIST_ITEM = struct tagDiscussionHistItem
    {
        CString strName;
        Schools eSchool;
        COleDateTime datMeeting;
    };
    using DiscussionItemHistList = list<S_DISCUSSION_HIST_ITEM>;
}

The above header file is included in another header file (B):

#include "ChristianLifeMinistryDefines.h"
using namespace CChristianLifeMinistryDefines;

enum class Schools
{
    kMain,
    kClass1,
    kClass2,

    kCount
};

The problem I have (and I understand why) is that Schools is referred to in the S_DISCUSSION_HIST_ITEM structure which is defined before the Schools enum.

Error C3646: 'eSchool': unknown override specifier

The enum was already defined in my project and can't be moved else things might break down when compiling.

What I have done is move the class definition from file B to file A. But was there another solution to this? I couldn't simply include header B in header A because I get a circular reference and I can't get my head around what I found on the internet.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • 1
    how about forward declaration ? https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c – Landstalker Dec 31 '20 at 09:18
  • @Landstalker When I try using `enum class Schools;` it then complains about `Schools` being ambiguous. – Andrew Truckle Dec 31 '20 at 10:56
  • 1
    Did you add the forward declaration, `enum class Schools;`, within `CChristianLifeMinistryDefines` namespace, by any chance? Header `B` defines it in the global namespace, so the forward declaration should be in the global namespace, too. Otherwise, you end up with declarations for two distinct enum types both named `Schools`. – Igor Tandetnik Dec 31 '20 at 14:02
  • 1
    Alternatively, move the whole definition of `Schools` to header A, before the definition of `S_DISCUSSION_HIST_ITEM`. Again, make sure to define it outside of `CChristianLifeMinistryDefines` namespace – Igor Tandetnik Dec 31 '20 at 14:04
  • @IgorTandetnik All good now. I accidentally declared it in the namespace by mistake. – Andrew Truckle Dec 31 '20 at 15:56

0 Answers0