用堆空间初始化引用,在适当的时候释放堆空间

代码:

#include 

using namespace std;

int CircleArea(){
        double* pd = new double;
        if(! pd){
                cout <<"error memory allocation !";
                return 1;
        }
//      cout << *pd <<"\n";
        double& rd = *pd;
        cout << "the radius is:";
        cin >> rd;
        cout << "the area of circle is "<< rd*rd*3.14 <

测试结果:

0
the radius is:2
the area of circle is 12.56
program successed.

你可能感兴趣的:(C++学习日记)