Basic typedef syntax

suggest change

A typedef declaration has the same syntax as a variable or function declaration, but it contains the word typedef. The presence of typedef causes the declaration to declare a type instead of a variable or function.

int T;         // T has type int
typedef int T; // T is an alias for int

int A[100];         // A has type "array of 100 ints"
typedef int A[100]; // A is an alias for the type "array of 100 ints"

Once a type alias has been defined, it can be used interchangeably with the original name of the type.

typedef int A[100];
// S is a struct containing an array of 100 ints
struct S {
    A data;
};

typedef never creates a distinct type. It only gives another way of referring to an existing type.

struct S {
    int f(int);
};
typedef int I;
// ok: defines int S::f(int)
I S::f(I x) { return x; }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Typedef and type aliases:
* Basic typedef syntax

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
130 Typedef and type aliases
134 Semaphore
136 Debugging
139 Mutexes
142 decltype