Why can’t I use a Javascript function before its definition inside a try block?

Firefox interprets function statements differently and apparently they broke declaration hoisting for the function declaration. ( A good read about named functions / declaration vs expression ) Why does Firefox interpret statements differently is because of the following code: if ( true ) { function test(){alert(“YAY”);} } else { function test(){alert(“FAIL”);} } test(); // should … Read more

Why must an enumeration’s size be provided when it is forward declared?

This has been standardized, proposal 2764: Forward declaration of enumerations (rev. 3) allowed the forward declaration of enums if you specify the underlying type, whereas before this was not possible. The main reason is that when the underlying type is not specified the size is implementation defined and can depend on the enumerator values. From … 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++ class forward declaration

Use forward declaration when possible. Suppose you want to define a new class B that uses objects of class A. B only uses references or pointers to A. Use forward declaration then you don’t need to include <A.h>. This will in turn speed a little bit the compilation. class A ; class B { private: … Read more