- výstup a vstup ze standardních proudů, metodu getline, setw, setprecision z knihoven iostream, iomanip.
- kompilace programu pomocí příkazu make a souboru Makefile.
- vytvoření hlavičkového souboru, příkazy preprocesoru zabraňující několikanásobnému vložení hlavičký, komentáře doxygenu
- definice třídy, konstruktor, metody, operátory přístupu, deklarace friend
- předefinování operátoru výstupu do proudu
soubor priklad1.cpp
#include <iostream>
#include <iomanip>
#include "car.h"
using namespace std;
int main() {
Vehicle v("Skoda 105", 2000);
cout << v << endl;
return 0;
}
soubor car.h
/** Library which contains class Vehicle
*/
#ifndef CAR_h
#define CAR_h
#include <string>
using namespace std;
class Vehicle
{
public:
Vehicle(string Type, int Price);
friend ostream& operator <<(ostream& out, Vehicle& v);
protected:
private:
int mPrice;
string mType;
};
ostream& operator <<(ostream& out, Vehicle& v);
#endif // _XX_h_
soubor car.cpp
#include <iostream>
#include "car.h"
using namespace std;
Vehicle::Vehicle(string Type, int Price): mType(Type), mPrice(Price) {}
ostream& operator <<(ostream& out, Vehicle& v)
{
return out << "Vehicle(" << v.mType \
<< ", Price: " << v.mPrice << ")";
}
Žádné komentáře:
Okomentovat