Forward declaration with unique_ptr? [duplicate]

It’s explicitly legal. The rule is that the types used to instantiate a template in the standard library must be complete, unless otherwise specified. In the case of unique_ptr, §20.7.1/5 says “[…] The template parameter T of unique_ptr may be an incomplete type.” There are certain operations on the pointer which require a complete type; … Read more

How do I forward-declare a function to avoid `NameError`s for functions defined later?

Wrap the invocation into a function of its own so that foo() def foo(): print “Hi!” will break, but def bar(): foo() def foo(): print “Hi!” bar() will work properly. The general rule in Python is that a function should be defined before its usage, which does not necessarily mean it needs to be higher … Read more

Should one use forward declarations instead of includes wherever possible?

The forward-declaration method is almost always better. (I can’t think of a situation where including a file where you can use a forward declaration is better, but I’m not gonna say it’s always better just in case). There are no downsides to forward-declaring classes, but I can think of some downsides for including headers unnecessarily: … Read more

Objective-C: Forward Class Declaration

It basically tells the compiler that the class RootViewController exists, without specifying what exactly it looks like (ie: its methods, properties, etc). You can use this to write code that includes RootViewController member variables without having to include the full class declaration. This is particularly useful in resolving circular dependencies – for example, where say … Read more