If you need 2-Dimension Array [m][n][m][n][m][n] where m, n are both variables, here are some devices:
+
T * * arr = new T * [m];
for( int i = 0; i < m; ++i){arr[ i] = new T[ n];
}
Note that, you have allocated T: n*m and T*: m, that is, you have additional T*: m, this is bad in Efficiency.
+ You need estimate the maximum of m, suppose it is M;
T (* arr)[ M] = new T[ n][ M];
This is good in Efficiency, but you always allocate T: n*M which are greater than n*m;
new T equals to new T[1]
new T[n] will allocate n items A1, A2, ..., An where Ai is a T, this operation return a pointer T * ptr;
new T[n][m] will allocate n items A1, A2, ..., An where Ai is a T[m], this operation return a pointer T (* ptr)[ m];
For generality, in new T[a][b][c]... only a could be variable, b, c, ... must be constant;
对于一个非递归的匿名函数, 可以用auto, auto func = [&](int _a) -> void{ };
但是, 如果该函数是(递归)的, 则会报错:
variable 'func' declared with deduced type 'auto' cannot appear in its own initializer func( _a)
必须要显式的定义他的类型, 即: function (而且必须要有[&])
int a;[](){//* `a, b` are not accessible.
};
[& or =](){//* `a` is accessible, but not `b`
};int b;
[&]修改外部变量int a = 123;
auto F = [&](){a = 666;
};
The value of a will be modified.
#字符串化#define F_( _a) #_a
The code auto ret = F_( a 1 * < ! hh abc 4); equals to const char * ret = "a 1 * < ! hh abc 4";