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

Why does a C++ friend class need a forward declaration only in other namespaces?

C++ Standard ISO/IEC 14882:2003(E) 7.3.1.2 Namespace member definitions Paragraph 3 Every name first declared in a namespace is a member of that namespace. If a friend declaration in a non-local class first declares a class or function (this implies that the name of the class or function is unqualified) the friend class or function is … Read more

c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)

If you will place your definitions in this order then the code will be compiled class Ball; class Player { public: void doSomething(Ball& ball); private: }; class Ball { public: Player& PlayerB; float ballPosX = 800; private: }; void Player::doSomething(Ball& ball) { ball.ballPosX += 10; // incomplete type error occurs here. } int main() { … Read more

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

tech