简体   繁体   中英

Dynamic initialization of array of pointers

class MyClass
{
    int **a;
    int *b[];

    MyClass()
    {
        a = new int*[10];
        b = new int*[10];
    }
};

In the above code I get a compilation error at the 2nd line inside the constructor (b = new int*[10]). It says error: incompatible types in assignment of int**' to int*[0u]'

Why is it so?

You can't assign to an array; you can initialize it or assign to its members. Your b member is invalid anyway since it is illegal to have an array of size 0; the syntax T b[] can only be used where an aggregate initializer is immediately provided allowing the compiler to infer the length of the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM