You have two different types:
int x[10];
Declares a type int[10]
. As you can see, the size of the array is part of the type.
int * y;
int. , . , 64- ( ).
, ++ 17:
template<class T>
std::enable_if_t<std::is_pointer_v<T>> foo(T ptr)
{
std::cout << "Called foo for a pointer type" << std::endl;
}
template<class T, int N>
void foo(T (&arr)[N])
{
std::cout << "Called foo for an array type of size " << N << std::endl;
}
foo
. , , ( ).
main:
int x[10];
int * y = nullptr;
foo(x);
foo(y);
, :
foo 10
foo
: Mark Ransom , y
, . , , (, malloc
new
) , .
, delete
, , ; (free
delete
) , . , , , 1 , 1 . ( , , )