0

I am reusing a class from an old project and it has the following:

Header File

// forward class declarations
class TimeZoneInfo;

class DateTime
{
public:
    // constructors
    DateTime();
    static TimeZoneInfo  m_Info;
};

Body File

TimeZoneInfo DateTime::m_Info; <-- Error Here
DateTime::DateTime()
{}
//blah blah

When I go to build this I get the error :

Error: Incomplete type is not allowed:

Why was this working before? (I am now using Visual Studio 2013)

And how can I solve this? Thanks

Harry Boy
  • 3,283
  • 12
  • 57
  • 102

2 Answers2

4

Why was this working before?

Impossible to say.

And how can I solve this?

Include the header that defines TimeZoneInfo from the source file, before the variable definition.

"Incomplete" means that the type has been declared, but not defined, so can only be used in limited ways. Specifically, you can declare a variable of an incomplete type, but can't define it.

Mike Seymour
  • 235,407
  • 25
  • 414
  • 617
1

It is ok to have a static incomplete type member. However, its type should be defined before the definition of the static member, i.e.

TimeZoneInfo DateTime::m_Info; // class TimeZoneInfo  must be fully defined before this line

Related: Static field of an incomplete type - is it legal?

Community
  • 1
  • 1
vsoftco
  • 52,188
  • 7
  • 109
  • 221