I'm trying to learn how to use the PIMPL idiom because it reduces compilation dependencies, which I've heard is recommended. So I have code that essentially looks like this.
Foo.h
class Foo
{
public:
Foo();
private:
class FooImpl;
std::unique_ptr<FooImpl> impl;
}
Foo.cpp
Foo::Foo():
impl(new FooImpl)
{
}
class Foo::FooImpl
{
public:
FooImpl();
}
But now I want to define FooImpl::FooImpl()
in a seperate .cpp file like I did with Foo::Foo()
, but how would I go about doing that?
EDIT: I've moved things around to get the code below, but now initializing impl
gives me an incomplete type compile error.
Foo.h
class Foo
{
public:
Foo();
private:
class FooImpl;
std::unique_ptr<FooImpl> impl;
}
Foo.cpp
#include "Foo.h"
Foo::Foo():
impl(new FooImpl)
{
}
FooImpl.cpp
#include "Foo.h"
class Foo::FooImpl
{
public:
FooImpl();
}