之前已经学习了C++类模板;类模板的写法和一般类的写法有很大的差别;不容易熟悉;下面再做一遍;
做一个椭圆类,成员有长轴长度和短轴长度;
- // ellipse.h: interface for the ellipse class.
- //
- //
-
- #if !defined(AFX_ELLIPSE_H__51CD537E_D0B0_40F9_AD63_92F0502C0430__INCLUDED_)
- #define AFX_ELLIPSE_H__51CD537E_D0B0_40F9_AD63_92F0502C0430__INCLUDED_
-
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
-
- template<class T1, class T2>
-
- class ellipse
- {
- public:
- ellipse(T1 a, T2 b) : older(a), lack(b){ }
-
- public:
- T1 getolder() const;
- void setolder(T1 a);
- T2 getlack() const;
- void setlack(T2 b);
-
- private:
- T1 older; //长轴长度
- T2 lack; //短轴长度
- };
-
- template<class T1, class T2>
- T1 ellipse
::getolder() const { - return older;
- }
-
- template<class T1, class T2>
- void ellipse
::setolder(T1 a){ - older = a;
- }
-
- template<class T1, class T2>
- T2 ellipse
::getlack() const{ - return lack;
- }
-
- template