Home > Back-end >  Pointer push_back a class, out of the mistake
Pointer push_back a class, out of the mistake

Time:09-26

Include
#include
#include
#include
using namespace std;
The class plane
{
Friend class information;
Public:
Float price;//the price of the ordinary seats, the first two market, such as the price is 1.5 times that of ordinary set
String the route [2];
Char seatP62 [12].
Char seatP124 [48].
Plane () {}
Void planeP62 (string Route1, string Route2, float Price)
{
The route [0]=Route1;//starting station
The route [1]=Route2;//termianl station
Price=price;
For (int I=0; i <12. I++)
{
SeatP62 [I]='Y'
}
}

};
Void storeP62 (vector * P62)
{
Ofstream fout (" planeP62. TXT ");
Fout & lt; For (int I=0; i {
Fout & lt; <[I]. (* P62) price & lt; <"\ t \ \ t t" & lt; <[I]. (* P62) route [0] <"\ t \ \ t t" & lt; <[I]. (* P62) route [1] For (int j=0; J & lt; 12. J++)
{
Fout & lt; <(* P62) [I] seatP62 [j] <"\ t \ \ t t";
}
Fout & lt; }
Fout. Close ();
}
Void readP62 (vector * PlaneP62)
{
int num;//the number of parts relate P62
Ifstream fin (" planeP62. TXT ", the ios: : in);
Fin & gt;> Num.//the number of P62

The plane plane;
For (int I=0; i {
Fin & gt;> PLANE. The price & gt;> PLANE. The route [0] & gt;> PLANE. The route [1];
For (int j=0; J & lt; 12. J++)
{
Fin & gt;> PLANE. SeatP62 [j];
}
PlaneP62 - & gt; Push_back (PLANE);
}
Fin. The close ();

}

Void the add ()
{
Vector * parts relate=NULL;
ReadP62 (Plane);
Int planetype;
String the route [2];
Float price;
Cout & lt; <"1 2 P124 P62" & lt; Cin & gt;> Planetype;
Cout & lt; <"Starting place:";
Cin & gt;> The route [0].
Cout & lt; <"The termianl station:";
Cin & gt;> The route [1].
Cout & lt; <"Price:";
Cin & gt;> Price;
The plane plane;
PLANE. PlaneP62 (route [0], the route [1], price);
parts relate - & gt; Push_back (PLANE);
StoreP62 (Plane);
}

Void main ()
{
The add ();
}
Run to the red font will program has a problem, don't pointer can push_back a class? Pointer definition is the form of the class

CodePudding user response:

At least have to new a vector Object,
 vector * parts relate=new vector (a); 
  • Related