1.The expression A->B is exactly equivalent to (*A).B for builtin types. If a user-defined operator->
is provided,operator->
is called again on the value that it returns, recursively, until the operator->
is reached that returns a plain pointer.
2
a.pointer to a array ref: (int[20])
int (&pRefArray)[20]
b. func that return an array ref
int (&pFuncReturnRefArray())[20]
c. typedef a funcpointer
typedef int (*FUN_POINTER)(void);
d. typedef a ref to a int[20]
typedef int (&REF_TO_INT_20)[20]
#include <iostream>
double test();
int aaaa(){return 100;}
typedef int (*FUN_POINTER)(void);
//typedef int (&ArrayRef)[10];
void test_typedef_pointer()
{
FUN_POINTER ff = aaaa;
std::cout<<ff()<<std::endl;
}
int global_array[10];
int (& fun_return_array_ref())[10]
{
return global_array;
}
void test_return_array_ref()
{
global_array[3] = 200;
int (&local_array)[10] = fun_return_array_ref();
std::cout<<local_array[3]<<std::endl;
}
//char (&ArraySizeImpl(T (&)[N]))[N]
typedef int (&ARRAY_REF)[10];
void test_typedef_arrayref()
{
//int a[10];
//int(&ref2)[10] = a;
ARRAY_REF (*fun)() = fun_return_array_ref;
global_array[3] = 220;
int (&local_array)[10] = fun();
std::cout<<local_array[3]<<std::endl;
}
int main(){
//std::cout<<sizeof(test())<<std::endl;
test_typedef_pointer();
test_return_array_ref();
test_typedef_arrayref();
return 0;
}