Closed karamellpelle closed 8 years ago
What's the actual error? I believe standard containers that store the objects dynamically on the heap, like vector
, deque
, etc, should generally accept forward-declared types as long as no methods are called that would need the full declaration. Perhaps there's an implicit class method being defined by the compiler that's trying to use methods on the deque
.
Here is my build output (the line numbers may be wrong; I've added and removed #include "source.h"
): alure.txt
The unit compiles without any problem with the line #include "source.h"
added to ./src/context.h . In order to (dynamically) allocate memory, the template has to know the datatype's size, which it can't know from a forward declaration. STL templates are typically defined in just 1 header file (since it is a template).
Yes, but as long as the method that does the allocation isn't invoked without the full type declaration, the compiler will ignore what isn't used, so it won't see that it doesn't know how to construct the type because it's not being asked to. Template class method instantiation is done when the method is first called, rather than when the object is declared.
But it seems C++ only recently started guaranteeing that you could this with STL containers, and only for certain containers, excluding deque. GCC handles deque in a way where this works, but OSX's compiler seems to want to know the type size to calculate a static const class member. So it's fixed in commit 2592d571106a697ad0533495dda524c593ce55bb.
On macOS Sierra, compilation fails for ./src/device.cpp because
alure::ALSource
is forward declared in ./src/context.h. ThemAllSources
member ofALContext
(line 78) requires the full datatype (more exactly thestd::deque
template needs the datatype). If I add#include "source.h"
at top of file, everything compiles fine.PS. For some odd reason it compiles on my Linux computer without any modification.