|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请看下面的代码:
template <class T>
struct point{
inline point():x(0),y(0) {}
inline point(T _x, T _y):x(_x),y(_y){}
T x, y;
};
有两个问题
(1)为什么在结构体point中还要内联两个point,这样做的作用是什么?
(2)在point结构体中内联point,这该怎么理解?
什么错?
分号想加几个就加几个的说
- template <class T>
- struct point{
- inline point():x(0),y(0) {}
- inline point(T _x, T _y):x(_x),y(_y){}
- T x, y;
- };
- template <class T, class A>
- struct orientedpoint: public point<T>{
- inline orientedpoint() : point<T>(0,0), theta(0) {};;;;;;;;;;;;;;;;;;;;;;
- inline orientedpoint(const point<T>& p);
- inline orientedpoint(T x, T y, A _theta): point<T>(x,y), theta(_theta){}
- inline void normalize();
- inline orientedpoint<T,A> rotate(A alpha){
- T s=sin(alpha), c=cos(alpha);
- A a=alpha+theta;
- a=atan2(sin(a),cos(a));
- return orientedpoint(
- c*this->x-s*this->y,
- s*this->x+c*this->y,
- a);
- }
- A theta;
- };
- int main(void) {
- orientedpoint<int, int> o;
- return 0;
- }
复制代码
|
|