mardi 18 avril 2017

C++ deprecated conversion from string constant to ‘char*’ and returned 1

I am having the deprecated conversion and return 1 exit error on below code. How can I clear the warning and returned 1 exit statue error?

Please advice

I can clear the type conversion error in main by adding to const to the char on initializing but still can not clean returned 1 exit statues

#include <iostream>
#include <string.h>
#include <assert.h>
using namespace std;
class vehicle
{
protected:
    int number, year, cost;
    char *make, *model, *bodyStyle, *color;
    public:
        vehicle(int = 0, int = 0, char* = NULL, char* = NULL, char* = NULL, char* = NULL, int = 0);
        vehicle(const vehicle &);
        virtual~vehicle();
        int getNumber() const;
        int getYear() const;
        char* getMake();
        char* getModel();
        char* getBodyStyle();
        char* getColor();
        int getCost() const;
        void Display();
};
vehicle::vehicle(int a, int b, char* ma1, char* mod1, char* bs1, char* c1, int cos)
{
    number = a;
    year = b;
    make = new char[strlen(ma1) + 1];
    assert(make);
    make = ma1;
    model = new char[strlen(mod1) + 1];
    assert(model);
    model = mod1;
    bodyStyle = new char[strlen(bs1) + 1];
    assert(bodyStyle);
    bodyStyle = bs1;
    color = new char[strlen(c1) + 1];
    assert(color);
    color = c1;
    cost = cos ;
}
int vehicle::getNumber() const
{
    return number;
}
int vehicle::getYear() const
{
    return year;
}
char* vehicle::getMake()
{
    return make;
}
char* vehicle::getModel()
{
    return model;
}
char* vehicle::getBodyStyle()
{
    return bodyStyle;
}
char* vehicle::getColor()
{
    return color;
}
int vehicle::getCost() const
{
    return cost;
}
vehicle :: ~vehicle()
{
    delete[] make;
    delete[]model;
    delete[] bodyStyle;
    delete color;
}
class Truckvehicle : public vehicle
{
    int passengers, mileage, grossWeight, tempGross;
    char *poweredBy;
    public:
    Truckvehicle(int = 0, int = 0, char* = NULL, char* = NULL, char* = NULL, char* = NULL, int = 0, int = 0, int = 0, int = 0, char * = NULL, int = 0);
    ~Truckvehicle();
    int getPassengers() const;
    int getMileage() const;
    int getGrossWeight() const;
    char* getPoweredBy();
    int getTempGross() const;
    void Display();
};
Truckvehicle::Truckvehicle(int a, int b, char* ma1, char* mod1, char* bs1, char* c1, int cos, int pass1, int mil, int gross, char* pb, int tg) :
    vehicle(a, b, ma1, mod1, bs1, c1, cos), passengers(pass1), mileage(mil), grossWeight(gross), poweredBy(pb), tempGross(tg)
{
    passengers = pass1;
    mileage = mil;
    grossWeight = gross;
    poweredBy = new char[strlen(pb) + 1];
    assert(poweredBy);
    poweredBy = pb;
    tempGross = tg;
}
int Truckvehicle::getPassengers() const
{
    return passengers;
}
int Truckvehicle::getMileage() const
{
    return mileage;
}
int Truckvehicle::getGrossWeight() const
{
    return grossWeight;
}
char* Truckvehicle::getPoweredBy()
{
    return poweredBy;
}
int Truckvehicle::getTempGross() const
{
    return tempGross;
}
Truckvehicle :: ~Truckvehicle()
{
    delete[] poweredBy;
}
void Truckvehicle::Display()
{
    cout << "Number       : " << number << endl;
    cout << "Year         : " << year << endl;
    cout << "Make         : " << make << endl;
    cout << "Model        : " << model << endl;
    cout << "Body Style   : " << bodyStyle << endl;
    cout << "Color        : " << color << endl;
    cout << "Cost         : " << cost << endl;
    cout << "Passengers   : " << passengers << endl;
    cout << "Mileage      : " << mileage << endl;
    cout << "GrossWeight  : " << grossWeight << endl;
    cout << "Temp Gross   : " << tempGross << endl;
    cout << "               " <<endl;
}
class MotorcycleVehicle : public vehicle
{
    int passengers, mileage;
    public:
        MotorcycleVehicle(int = 0, int = 0, char* = NULL, char* = NULL, char* = NULL, char* = NULL, int = 0, int = 0, int = 0);
        ~MotorcycleVehicle();
        int getpassengers() const;
        int getmileage() const;
        void Display();
};
MotorcycleVehicle::MotorcycleVehicle(int a, int b, char* ma1, char* mod1, char* bs1, char* c1, int cos, int pass1, int mil) :
     vehicle(a, b, ma1, mod1, bs1, c1, cos), passengers(pass1), mileage(mil)
{
    passengers = pass1;
    mileage = mil;
}
int MotorcycleVehicle::getpassengers() const
{
    return passengers;
}
int MotorcycleVehicle::getmileage() const
{
    return mileage;
}
MotorcycleVehicle :: ~MotorcycleVehicle()
{
}
void MotorcycleVehicle :: Display()
{
    cout << "Number       : " << number << endl;
    cout << "Year         : " << year << endl;
    cout << "Make         : " << make << endl;
    cout << "Model        : " << model << endl;
    cout << "Body Style   : " << bodyStyle << endl;
    cout << "Color        : " << color << endl;
    cout << "Cost         : " << cost << endl;
    cout << "Passengers   : " << passengers << endl;
    cout << "Mileage      : " << mileage << endl;
    cout << "               " << endl;
}
class TrailerVehicle : public vehicle
{
    int grossweight;
    public:
        TrailerVehicle(int = 0, int = 0, char* = NULL, char* = NULL, char* = NULL, char* = NULL, int = 0, int = 0);
        ~TrailerVehicle();
        int getgrossweight() const;
        void Display();
};
TrailerVehicle::TrailerVehicle(int a, int b, char* ma1, char* mod1, char* bs1, char* c1, int cos, int gross) : vehicle(a, b, ma1, mod1, bs1, c1, cos), grossweight(gross)
{
    grossweight = gross;
}
int TrailerVehicle::getgrossweight() const
{
    return grossweight;
}
TrailerVehicle::~TrailerVehicle()
{
}
void TrailerVehicle::Display()
{
    cout << "Number       : " << number << endl;
    cout << "Year         : " << year << endl;
    cout << "Make         : " << make << endl;
    cout << "Model        : " << model << endl;
    cout << "Body Style   : " << bodyStyle << endl;
    cout << "Color        : " << color << endl;
    cout << "Cost         : " << cost << endl;
    cout << "GrossWeight  : " << grossweight << endl;
}
class TravelTrailerVehicle : public vehicle
{
    int passengers, mileage, bodynumber, length,grossWeight ;
    char* poweredby;
    public:
        TravelTrailerVehicle(int = 0, int = 0, char* = NULL, char* = NULL, char* = NULL, char* = NULL, int = 0, int = 0, int = 0,int = 0, char * = NULL, int = 0, int = 0);
        ~TravelTrailerVehicle();
        int getpassengers() const;
        int getlength() const;
        int getmileage() const;
        int getbodynumber() const;
        char* getpoweredby();
        int getGrossWeight() const;
        void Display();
};
TravelTrailerVehicle::TravelTrailerVehicle(int a, int b, char* ma1, char* mod1, char* bs1, char* c1, int cos,int gross, int pass1, int mil, char* pb,int bod,int len) :
     vehicle(a, b, ma1, mod1, bs1, c1, cos), passengers(pass1),length(len), mileage(mil),bodynumber(bod), poweredby(pb),grossWeight(gross)
{
    passengers = pass1;
    length = len;
    mileage = mil;
    bodynumber = bod;
    poweredby = new char[strlen(pb) + 1];
    assert(poweredby);
    poweredby = pb;
    grossWeight=gross;
}
int TravelTrailerVehicle::getpassengers() const
{
    return passengers;
}
int TravelTrailerVehicle::getmileage() const
{
    return mileage;
}
int TravelTrailerVehicle::getlength() const
{
    return length;
}
char* TravelTrailerVehicle::getpoweredby()
{
    return poweredby;
}
TravelTrailerVehicle :: ~TravelTrailerVehicle()
{
    delete[] poweredby;
}
int TravelTrailerVehicle::getGrossWeight() const
{
    return grossWeight;
}
void TravelTrailerVehicle::Display()
{
    cout << "Number       : " << number << endl;
    cout << "Year         : " << year << endl;
    cout << "Make         : " << make << endl;
    cout << "Model        : " << model << endl;
    cout << "Body Style   : " << bodyStyle << endl;
    cout << "Color        : " << color << endl;
    cout << "Cost         : " << cost << endl;
    cout << "Passengers   : " << passengers << endl;
    cout << "Length       : " << length << endl;
    cout << "Mileage      : " << mileage << endl;
    cout << "Body Number  : " << bodynumber << endl;
    cout << "Powered By   : " << poweredby << endl;
    cout << "               " << endl;
}
int main()
{
    vehicle *List[]={
    new Truckvehicle (111111, 2014, (char *)"Toyota","Tacoma", "4X4", "Black", 25000, 2, 15000,333333, "Gas", 222222),
    new MotorcycleVehicle (2222222, 2015, "Honda", "Gold Wing", "Coupe", "Red", 5000, 1, 3250),
    new TravelTrailerVehicle (123456789, 2015,"Toyota","Camry", "Coupe", "Red",20000, 666666, 5, 9855,"Gas", 222222, 20),
    new TrailerVehicle (123456789, 2015,"Toyota ","Camry", "Coupe", "Red",10000, 666666)
    };
for ( int i = 0; i< 3; i++)
    List [i] -> Display();

for ( int j = 0; j< 3; j++)
    delete List [j] ;

    return 0;
}






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire