August 2012
Intermediate to advanced
976 pages
30h 17m
English
Because we cannot copy an array, a function cannot return an array. However, a function can return a pointer or a reference to an array (§ 3.5.1, p. 114). Unfortunately, the syntax used to define functions that return pointers or references to arrays can be intimidating. Fortunately, there are ways to simplify such declarations. The most straightforward way is to use a type alias (§ 2.5.1, p. 67):
typedef int arrT[10]; // arrT is a synonym for the type array of ten intsusing arrT = int[10]; // equivalent declaration of arrT; see § 2.5.1 (p. 68)arrT* func(int i); // func returns a pointer to an array of ten ints
Here arrT is a synonym for an array of ten ints. Because we cannot return an array, we define ...
Read now
Unlock full access