64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
template <typename T>
class Point
{
T x,y;
public:
Point(T x1,T y1){x=x1;y=y1;cout<<x<<","<<y<<endl;}
Point(const Point& p1){x=p1.x;y=p1.y;}
};
template <typename T>
class LineDerive:public Point<T>
{
T x2,y2;
public:
LineDerive(T i1,T j1,T i2,T j2):Point<T>(i1,j1){x2=i2;y2=j2;}
};
template <typename T>
class LineInclude
{
Point<T> p1,p2;
public:
LineInclude(T i1,T j1,T i2,T j2):p1(i1,j1),p2(i2,j2){}
LineInclude(const Point& pt1,const Point& pt2):p1(pt1),p2(pt2){}
};
void main()
{
Point<int> p1(1,2),p2(3,4);
LineDerive<int> ld1(5,6,7,8);
LineInclude<int> li1(9,10,11,12);
LineInclude<int> li2(p1,p2); //这一句报错,怎么改?
}
#include <iostream>
using namespace std;
template <typename T>
class Point
{
T x,y;
public:
Point(T x1,T y1){x=x1;y=y1;cout<<x<<","<<y<<endl;}
Point(const Point& p1){x=p1.x;y=p1.y;}
};
template <typename T>
class LineDerive:public Point<T>
{
T x2,y2;
public:
LineDerive(T i1,T j1,T i2,T j2):Point<T>(i1,j1){x2=i2;y2=j2;}
};
template <typename T>
class LineInclude
{
Point<T> p1,p2;
public:
LineInclude(T i1,T j1,T i2,T j2):p1(i1,j1),p2(i2,j2){}
LineInclude(const Point<T>& pt1,const Point<T>& pt2):p1(pt1),p2(pt2){}//参数类型因该为模板类型
};
void main()
{
Point<int> p1(1,2),p2(3,4);
LineDerive<int> ld1(5,6,7,8);
LineInclude<int> li1(9,10,11,12);
LineInclude<int> li2(p1,p2); //这一句报错,怎么改?
}
1,2
3,4
5,6
9,10
11,12
请按任意键继续. . .
#include <iostream>
using namespace std;
template <typename T>
class Point
{
T x,y;
public:
Point(T x1,T y1){x=x1;y=y1;cout<<x<<","<<y<<endl;}
Point(const Point& p1){x=p1.x;y=p1.y;}
};
template <typename T>
class LineDerive:public Point<T>
{
T x2,y2;
public:
LineDerive(T i1,T j1,T i2,T j2):Point<T>(i1,j1){x2=i2;y2=j2;}
};
template <typename T>
class LineInclude
{
Point<T> p1,p2;
public:
LineInclude(T i1,T j1,T i2,T j2):p1(i1,j1),p2(i2,j2){}
LineInclude(const Point<T>& pt1,const Point<T>& pt2):p1(pt1),p2(pt2){}//here
};
void main()
{
Point<int> p1(1,2),p2(3,4);
LineDerive<int> ld1(5,6,7,8);
LineInclude<int> li1(9,10,11,12);
LineInclude<int> li2(p1,p2); //这一句报错,怎么改?
}