Question

I'm starting my post with the questions interested for me:

Q1: Is it true that declaration introduced one or more name into translation unit which denote type?

Q2: (If answer for Q1 is positive) How does compiler determine type of name introduced by declaration? Consider the following declaration:

This questions appears when I've started to read 3rd clause of c++ working draft.

An entity is a value, object, reference, function, enumerator, type, class member, template, template specialization, namespace, parameter pack, or this.

A name is a use of an identifier (2.11), operator-function-id (13.5), literal-operator-id (13.5.8), conversion function-id (12.3.2), or template-id (14.2) that denotes an entity or label (6.6.4, 6.1).

List<Observer *> *_observers;

This declaration introduced _observers into the current scope. I want to understand how does compiler determine the type of _observers? I'm interested in the formal algorithm described in the c++ spec.

Was it helpful?

Solution

A declaration can introduce a type, a function, a variable.

class A;  // This declares a type, A
A* aPtr;  // This declares a variable, aPtr
          // The type of aPtr is A*
A foo();  // This declares a function, foo.

In your case,

List<Observer*> *_Observers;  // Declares a variable, _observers.
                              // The type of _observers is List<Observer*>*.
                              // For this to be a valid declarion, the types List,
                              // a class template, and Observer must be known 
                              // (declared or defined) before the
                              // variable declaration.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top