This is because you instantiate
cgoobar
, it needs
cgoobar
information such as its class size, forward declaration cannot help you. Forward declaration can only help when declaring
cgoobar
pointer in header because pointer size is always the same (32-bit or 64-bit depending on the platform). One solution is to put your class in header and functions in their own cpp file.
class cfoobar
{
public:
void foobar_method();
};
class cgoobar
{
public:
void goobar_method();
};
#include "cfoobar.h"
#include "cgoobar.h"
void cfoobar::foobar_method()
{
auto goobar_ptr = new cgoobar;
goobar_ptr->goobar_method();
}
#include "cgoobar.h"
void cgoobar::goobar_method()
{
}