Hujuk
Hujuk

Reputation: 23

What is type int(*)[]

I've class with matrix and getter

class A
{
  int matrix[20][10];
 public:
   auto getter(){return matrix;}
};

What is a type that auto returned? And how to return it without using auto

Upvotes: 2

Views: 269

Answers (3)

Ekin Ersan
Ekin Ersan

Reputation: 65

Auto means type is going to be decided according to what you returned. So in this case i believe it is and array that holds int arrays. You can just put the type you want to return instead of auto.

Upvotes: 0

You don't really want to specify the return type without auto or a type alias. The usual rules for declarators make it quite ugly. But here it is, just follow the spiral rule:

int (*getter())[10] {return matrix;}

Upvotes: 2

gsamaras
gsamaras

Reputation: 73424

auto here gets the type that the function should return automatically. In that case that type is:

int (*)[10]

Upvotes: 0

Related Questions