2.1 Type Aliases #
Created Monday 18 May 2020
There are two ways to create type aliases:
- typedef
typedef int powder; // alias at last
- using keyword
using powder = int; // # alias at the proper place, like a declaration
Both are equivalent, using is more intuitive; Note:
- Remember that for pointers aliases(i.e the aliases for pointer type, apply for all the variables in a list declaration) - This is pretty intuitive (HOW IT should have been).
using pint = int*;
pint a, b, c; // same as int*a; int*b; int*c;
/*
int* a, b , c; // Wrong interpretation
*/
- Replacing does not always, work - i.e semantics matter. Beware of const
typedef char *pstring;
const pstring x = 0; // cstr is a constant pointer to char
// direct replacement
const char * x; // wrong here
char const * p; // correct - we want to make the alias as a constant