Edit: I know that one can't forward declare typedefs, and there are many qs concluding just that (indeed, I linked to one). But none of them explain why this is disallowed. I'm not looking for a workaround. I want to understand the rationale.
it turns out that you can't forward-declare a using-directive (or typedef). I.e. you can't do this:
Interface:
class Impl;
using Concrete = shared_ptr<Impl>;
Implementation:
using Impl = std::function<Foo(const Foo&)>; //DOES NOT COMPILE
Instead you have to create a one-element class Impl
that wraps the std::function.
What's the rationale behind forbidding this? AFAICS all one can do with a forward-declared type like class Impl
is to store pointers or references to Impl
... and that works even if Impl
is later defined to be a primitive like int
or a function pointer or et cetera..
(Note that typename Impl
doesn't seem to be a valid way of forward declaring a type.)