Search code examples
c++auto

Why does this need auto?


auto data = new char[480][640][3]();
char data = new char[480][640][3]();

First works. Second doesnt. Why? Isn't auto supposed to just replace itself with the type of the initializer?


Solution

  • Because the type isn't char. The type is char(*)[640][3] and the declaration would be written as

    char (*data)[640][3] = new char[480][640][3]();