生成结果为:
-85899340
171798....
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
template <class T>
class Cylinder
{
private:
int m_r,m_x,m_y,m_h,PI,V,S;
public:
Cylinder(){m_r=0;m_x=0;m_y=0;m_h=0;PI=3;}
Cylinder(T r,T x,T y,T h){ m_r=r;m_x=x;m_y=y;m_h=h;}
Cylinder(Cylinder &x){ m_r=x.m_r;m_x=x.m_x;m_y=x.m_y;m_h=x.m_h;}
int GetVolume() { return V=PI*m_r*m_r*m_h;}
int GetSurface(){ return S=2*PI*m_h*m_r+PI*m_r*m_r;}
friend ostream &operator<<<T>(ostream &os, Cylinder &cyl)
{
os<<cyl.GetSurface()<<" "<<cyl.GetVolume();
return os;
}
};
int main()
{ Cylinder<int> a (1,1,1,1);
cout<<a.GetVolume()<<"是圆柱体的体积"<<endl;
cout<<a.GetSurface()<<"是圆柱体的表面积"<<endl;
return 0;}