2.1 Type Aliases #

Created Monday 18 May 2020

There are two ways to create type aliases:

  1. typedef
typedef int powder;	// alias at last
  1. using keyword
using powder = int; // # alias at the proper place, like a declaration

Both are equivalent, using is more intuitive; Note:

  1. 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
*/
  1. 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