1

I have a header file class.hpp that contains my main object

class Class {
public:
  Class();
  ~Class();
private:
  struct Impl;
  std::unique_ptr<Impl> impl;

};

I then have my main implementation class_impl.cpp

#include "Class.hpp"

struct Class::Impl {
  int x;

};

Class::Class() : impl(new Impl)
{

}

I now want to have another class_impl_extended.cpp because class_impl.cpp is getting very long.

I tried to do this and access impl but this fails to compile with:

error: invalid use of incomplete type 'struct Class::Impl'
raaj
  • 2,869
  • 4
  • 38
  • 58
  • How is `class_impl_extended` extening `Impl`? Inheritance? Polymorhpism yes/no? Composition? Please show more details. – Ted Lyngmo Sep 01 '22 at 00:11
  • 7
    If a file gets too long, a split is a band aid (of the cheap kind). The class likely has a bloated api, or too many responsibilities. Both can be addressed by offshoring some of the work to smaller, more focused types. – StoryTeller - Unslander Monica Sep 01 '22 at 00:11
  • 1
    Are you providing the `struct Class::Impl` in both files? Or in a common-but-private header file? – Eljay Sep 01 '22 at 00:11

0 Answers0