1

I have a class structure where I have some member variables declared like this:

/* HEADER */
#ifndef SRC_HEADER_H
#define SRC_HEADER_H

class Service {
 private:
  typedef boost::multi_index_container<...> Checkpoints;
  Checkpoints checkpoints_ GUARDED_BY(mutex_);
};

#endif

Then I have the source file with the implementation:

#include "src/header.h"

/* some functions which use `checkpoints_` */

Is there a way I could move the typedef from the header file to the source file and keep the member checkpoints_ there in the header file only? I am trying to make the header file lighter since this multi_index_container might become a heavy container with repercussions on compile time.

Vaibhav
  • 346
  • 2
  • 12
  • Have you tried `class Checkpoints;` in the header? – Sebastian Jan 17 '22 at 10:19
  • @Sebastian: You can’t forward declare a typedef like that, even if it happens to be exactly a class type. – Davis Herring Jan 17 '22 at 15:05
  • Oh thx. What is the size of _checkpoints? You tagged pimpl, change member variable to pointer or wrapper class, which just contains a pointer? – Sebastian Jan 17 '22 at 15:50
  • 1
    Decided to move forward with the pimpl approach. Luckily, I found something I needed at https://stackoverflow.com/questions/20620243/typedef-private-struct-prototype-in-source-file – Vaibhav Jan 17 '22 at 16:46

1 Answers1

1

You can't forward declare a typedef in a header file, however, the pImpl idiom can be taken as inspiration to implement the thing in the question.

I found the relevant information here: Typedef private struct prototype in source file

Vaibhav
  • 346
  • 2
  • 12