[Visual Studio 2017]Not able to successfully use circular includes

  • Thread starter Thread starter primem0ver
  • Start date Start date
P

primem0ver

Guest
I used to be able to do this in previous versions. (My most recent Professional version was 2012 before downloading community version of 2017).

I have two classes that have inline functions which call a function in the other class. In order to do this, the header files for the two classes must be able to include each other. It appears that Visual Studio 2017 does not allow this. It gives me all kinds of errors about undefined classes (and resulting errors) and does not color code the page properly when two header files include each other. This is true, even if I have include guards in place.

The code below is an example of what I mean.

A.h

#ifndef A_H
#define A_H
#include "B.h"

class A
{
public:
A();
~A();

inline void foo(B* b) { b->bar(); }
void bar();
};

#endif

B.h

#ifndef B_H
#define B_H

#include "A.h"
class B
{
public:
B();
~B();

inline void foo(A* a) { a->bar(); }
void bar();
};

#endif

This also does not work if I do both the include and the body of the inline function after the class definition. Using #pragma once doesn't work either as A is not defined when compiling class B.

Continue reading...
 
Back
Top