Home > Back-end >  Excuse me template class - this code which is wrong
Excuse me template class - this code which is wrong

Time:09-21

# # ifndef SHAPE_H
# define SHAPE_H
# include//the mutator
# include
# include
using namespace std;
The class Shape {
Int obj_id;//object identifiers
String des;//describe object feature
Public:
Shape (int a, string b) : obj_id (a), the des (b) {}//constructor
Shape (Shape& P) {obj_id=p.o bj_id; Des=conviction yourself es; }//copy constructor
Shape () {}//constructor
Shape& Operator=(Shape& P) {obj_id=p.o bj_id; Des=conviction yourself es; Return * this; }//assignment function
Void Setdes (string a) {des=a; }
String Getdes () {return des; }
Int Getid () {return obj_id; }
Virtual float Area ()=0;//pure virtual function
Virtual void WriteToFile (ofstream& O)=0;//pure virtual function
};
# endif

# include "Shape. H"
The class Point: public Shape {//a derived class
Float x, y;
Static int count;
Public:
Point (int a, float b, c, float string d) : x (b), y (c), Shape (a, d) {count++; }//constructor
Point (Point& P) : x (p.x), y (p.y), Shape (p) {count++; }////copy constructor
Point () {count++; }///constructor
Point& Operator=(Point& P);//
Virtual float Area () {return 0; }
Virtual void WriteToFile (ofstream& O);//need to implement
Static int Getcount () {return count; }
Float Getx () {return x; }
Float Gety () {return y; }
Friend ifstream& Operator<(ifstream& In Point& P);
};
Int Point: : count=0;
Ifstream& Point: : operator<(ifstream& In Point& P)
{
int b;
String a;
CoutIn> b> P.x & gt;> P.y.
In> a;
Shape: : Setdes (a);
Return in;
}
The void Point: : WriteToFile (ofstream& O)
{
O}

Ostream& Operator<(ostream& O, Point& P)
{
Oreturn o;
}
Point& Point: : operator=(Point& P)//
{
X=p.G etx ();
Y=p.G ety ();
Shape: : operator=(p);
Return * this;
}
Int main ()
{
Ofstream fileout "point. TXT", the ios: : (out);
Point p1 (1, 2, 1, "House");
Point p2 (2 and 4, "at");
Point p3 (three, four, five, "Park");
Point p4 (p3);
CoutCoutCoutP4=p;
CoutP1. WriteToFile (fileout);
P2. WriteToFile (fileout);
P3. WriteToFile (fileout);
CoutFileout. Close ();
return 0;
}
How to dev compiler don't
  • Related