类中构造函数问题
#include <iostream.h>const float pi=3.14159;
const float fenceprice=35;
const float concreteprice=20;
class circle
{float radius;
public:
circle(float r);
float circumference();
float area();
};
circle::circle(float r) //没有这句无法运行,请问下这里为什么要这样写?
{radius=r;} //radius=r但程序从没给r赋值啊?
float circle::circumference()
{return 2*pi*radius;}
float circle::area()
{return pi*radius*radius;}
void main()
{float radius,fencecost,concretecost;
cin>>radius;
circle pool(radius);
circle poolrim(radius+3);
fencecost=poolrim.circumference()*fenceprice;
cout<<"langanqian="<<fencecost;
concretecost=(poolrim.area()-pool.area())*concreteprice;
cout<<"ludaoqian="<<concretecost<<endl;
}
问题在程序里