here's how the code starts:
-
#include <vector>
-
using namespace std;
-
-
template <class T>
-
class Point
-
{
-
public:
-
T x;
-
T y;
-
Point(T _x=0, T _y=0): x(_x), y(_y){}
-
void move(T _X, T _y)
-
{
-
x += _X;
-
y += _y;
-
}
-
};
-
/******************************************************/
-
class Shape
-
{
-
public:
-
virtual void print()=0;
-
virtual Shape* clone()=0;
-
virtual void extend(int i)=0;
-
virtual void move(int x,int y)=0;
-
};
-
/******************************************************/
-
template <int size=10>
-
class Picture
-
{
-
vector<Shape*> vec;
-
-
public:
-
void add(Shape* s)
-
{
-
if (s != NULL) vec.push_back(s);
-
return;
-
}
-
Picture();
-
~Picture();
-
void print_all();
-
void add(unsigned int i, Shape* s);
-
void remove(unsigned int i);
-
void print(unsigned int i);
-
void extend_all(int i);
-
void extend(unsigned int i, int x);
-
void move_all(int x, int y);
-
void move(unsigned int i, int x, int y);
-
};
-
/******************************************************/
-
template <class X>
-
class Circle: public Shape
-
{
-
protected:
-
X radius;
-
Point<X> center;
-
static const X step;
-
-
public:
-
Circle();
-
Circle(X, X, X);
-
Circle(Point<X>, X);
-
virtual void print();
-
virtual Circle<X>* clone();
-
virtual void extend(int i);
-
virtual void move(int x,int y);
-
};
-
/******************************************************/
-
template <class X>
-
class Square: public Shape
-
{
-
protected:
-
Point<X> point;
-
X limp;
-
static const X step;
-
-
public:
-
Square();
-
Square(X, X, X);
-
Square(Point<X>, X);
-
virtual void print();
-
virtual Square<X>* clone();
-
virtual void extend(int i);
-
virtual void move(int x, int y);
-
};
-
/******************************************************/
-
template <class X>
-
class Triangle: public Shape
-
{
-
private:
-
Point<X> head_1, head_2, head_3;
-
static const X step;
-
-
public:
-
Triangle();
-
Triangle(X, X, X, X, X, X);
-
Triangle(Point<X>, Point<X>, Point<X>);
-
void print();
-
void extend(int i);
-
Triangle<X>* clone();
-
void move(int x, int y);
-
};
-
/******************************************************/
-
template <class X>
-
class Ellipse: public Circle<X>
-
{
-
protected:
-
X radius_2;
-
-
public:
-
Ellipse();
-
Ellipse(X, X, X, X);
-
Ellipse(Point<X>, X, X);
-
void print();
-
Ellipse<X>* clone();
-
void extend(int i);
-
void move(int x, int y);
-
};
-
/******************************************************/
-
template <class X>
-
class Rectangle: public Square<X>
-
{
-
private:
-
X vertical;
-
-
public:
-
Rectangle();
-
Rectangle(X, X, X, X);
-
Rectangle(Point<X>, X, X);
-
void print();
-
Rectangle<X>* clone();
-
void extend(int i);
-
void move(int x, int y);
-
};
-
/******************************************************/
-
i didn't use
#include<vector> and
using namespace std;, then the compiler gave the errors in first post.
now, after adding these (#include<..> and using namespace..) it gives linker errors !
here are the errors:
1>shapes.obj : error LNK2001: unresolved external symbol "private: static char const Triangle<char>::step" (?step@?$Triangle@D@@0DB)
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Picture<6>::~Picture<6>(void)" (??1?$Picture@$05@@QAE@XZ) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::add(unsigned int,class Shape *)" (?add@?$Picture@$05@@QAEXIPAVShape@@@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Triangle<int>::Triangle<int>(int,int,int,int,int,i nt)" (??0?$Triangle@H@@QAE@HHHHHH@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::extend_all(int)" (?extend_all@?$Picture@$05@@QAEXH@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::remove(unsigned int)" (?remove@?$Picture@$05@@QAEXI@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::move(unsigned int,int,int)" (?move@?$Picture@$05@@QAEXIHH@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::move_all(int,int)" (?move_all@?$Picture@$05@@QAEXHH@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::print(unsigned int)" (?print@?$Picture@$05@@QAEXI@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: void __thiscall Picture<6>::print_all(void)" (?print_all@?$Picture@$05@@QAEXXZ) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Triangle<char>::Triangle<char>(void)" (??0?$Triangle@D@@QAE@XZ) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Picture<6>::Picture<6>(void)" (??0?$Picture@$05@@QAE@XZ) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Rectangle<long>::Rectangle<long>(class Point<long>,long,long)" (??0?$Rectangle@J@@QAE@V?$Point@J@@JJ@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Square<unsigned int>::Square<unsigned int>(unsigned int,unsigned int,unsigned int)" (??0?$Square@I@@QAE@III@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Ellipse<double>::Ellipse<double>(class Point<double>,double,double)" (??0?$Ellipse@N@@QAE@V?$Point@N@@NN@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Circle<char>::Circle<char>(char,char,char)" (??0?$Circle@D@@QAE@DDD@Z) referenced in function _main
1>shapesMain.obj : error LNK2019: unresolved external symbol "public: __thiscall Circle<int>::Circle<int>(void)" (??0?$Circle@H@@QAE@XZ) referenced in function _main
and here's my main:
- #include <iostream>
-
#include "shapes.h"
-
-
-
template<> const int Circle<int>::step = 1;
-
template<> const double Circle<double>::step = 0.1;
-
-
template<> const int Square<int>::step = 1;
-
template<> const double Square<double>::step = 0.1;
-
-
template<> const int Triangle<int>::step = 1;
-
template<> const double Triangle<double>::step = 0.1;
-
-
-
int main()
-
{
-
Circle<int> *c = new Circle<int>();
-
c->print();
-
Circle<char> *ch = new Circle<char>('2','3','3');
-
ch->print();
-
Ellipse<double> *e = new Ellipse<double>(Point<double>(1,2),2.2,5.6);
-
e->print();
-
Square<unsigned int> *s = new Square<unsigned int>(3,4,5);
-
s->print();
-
Rectangle<long> *r = new Rectangle<long>(Point<long>(1,3),2,3);
-
r->print();
-
cin.get();
-
Picture<6> pic;
-
-
pic.add(c);
-
pic.add(e);
-
pic.add(ch);
-
pic.add(s);
-
pic.add(r);
-
delete c;
-
delete ch;
-
delete e;
-
delete s;
-
delete r;
-
pic.add(new Triangle<char>());
-
pic.print_all();
-
pic.print(2);
-
pic.move_all(20,3);
-
pic.move(2,5,6);
-
pic.remove(3);
-
pic.print_all();
-
pic.extend_all(-2);
-
pic.add(4,new Triangle<int>(2,3,4,4,5,5));
-
-
return 0;
-
}
-