#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
template <class T>
class Cylinder
{
private:
Cylinder 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 GetVolume() { return V=PI*m_r*m_r*m_h;}
Cylinder 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.GetSurface()<<"是圆柱体的体积"<<endl;
cout<<a.GetSurface()<<"是圆柱体的表面积"<<endl;
return 0;}
Cylinder m_r,m_x,m_y,m_h,PI,V,S;
Cylinder GetVolume() { return V=PI*m_r*m_r*m_h;}
Cylinder GetSurface(){ return S=2*PI*m_h*m_r+PI*m_r*m_r;}
以上几句感觉怪怪的。m_r,m_x,m_y,m_h,PI,V,S 应该是<T>, 返回的应该是泛型<T>。
还有你带参构造函数里面,PI也没有赋值。