Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong report of header file "does not need to be included; use a forward declaration instead" #94

Open
omichel opened this issue Mar 4, 2016 · 0 comments

Comments

@omichel
Copy link

omichel commented Mar 4, 2016

I have the following include files:
A.hpp

class A {
public:
  A();
  int value() { return mValue; }
private:
  int mValue;
};

B.hpp

#include "A.hpp"

class B {
public:
  B();
  int getAValue() { return mA->value(); }
private:
  A *mA;
};

And here is what cppclean tells me:

$ cppclean B.hpp
B.hpp:1: 'A.hpp' does not need to be #included; use a forward declaration instead

However if I replace #include "A.cpp" with class A;, it doesn't compile anymore:

$ gcc B.hpp
B.hpp: In member function 'int B::getAValue()':
B.hpp:6:30: error: invalid use of incomplete type 'class A'
   int getAValue() { return mA->value(); }
                              ^
B.hpp:2:7: note: forward declaration of 'class A'
 class A;
       ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant