#include<iostream>
int& fun();
int main()
{
int p=fun();
std::cout<<p;
return 0;
}
int & fun()
{
int a=10;
return a;
}
invalid initialization of non-const reference of type 'int&' from a temporary of type 'int*'' is because you are returning & a and not a`.
, .
. , , - . , .
!
:
#include<iostream>
int* fun();
int main()
{
int *p =fun();
std::cout<< *p;
delete p;
return 0;
}
int* fun()
{
int *a = new int;
*a = 10;
return a;
}