Say I want to deal with an array of pointers to functions that take no arguments and return no arguments. I can declare an array of such pointers like so: void (*pFuncs[5])(void);
But if I want to use new to allocate memory I get stuck:
1 2
void (**pFuncs)(void); //is this right?
pFuncs = new *what to put here?*
In addition to using typedefs, use containers so you that you don't need to use new. And you don't end up with an extra level of indirection like Smac89 did. =P
as for doing that new without a typedef, the little-known catch is that if the type-id you're new'ing includes any parentheses, it must be parenthesized:
as for doing that new without a typedef, the little-known catch is that if the type-id you're new'ing includes any parentheses, it must be parenthesized:
I suspect that this is because of default-initialization versus value-initialization syntax:
1 2
int *a = newint; // default initialization, *a is garbage
int *b = newint(); // value initialization, *b is 0
@Catfish it breaks at grammar level even without taking initializers into account: the standard's example in 5.3.4[expr.new]/4 is
newint(*[10])(); // error
is ill-formed because the binding is (newint) (*[10])(); // error
Instead, the explicitly parenthesized version of the new operator can be used to create objects of compound
types: new (int (*[10])());
remember, new is an operator, like sizeof or +. It can be anywhere in an expression.