| |

VerySource

 Forgot password?
 Register
Search
View: 608|Reply: 2

Help !!!!

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-1 13:00:02
| Show all posts |Read mode
#include <iostream.h>
class Vehicle {
public:
Vehicle (double x)
{
cost = x;
}
~ Vehicle () {}
virtual void show ()
{
cout << "I am a vehicle.";
}
virtual void costs ()
{
cout << "Cost is" << cost;
}
        private:
double cost;
};
class Car: public Vehicle {
public:
Car (double x)
{
cost = x;
}
~ Car () {}
void show ()
{
cout << "I am a car.";
}
void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
class Truck: public Vehicle {
public:
Truck (double x)
{
cost = x;
}
~ Truck () {}
void show ()
{
cout << "I am a truck.";
}
void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
void callcost (Vehicle&);
main ()
{
Vehicle vehi (1.5);
callcost (vehi);
Car c (3.8);
callcost (c);
Truck tr (5.8);
callcost (tr);
return 0;
}
void callcost (Vehicle&vehi)
{
vehi.show ();
vehi.costs ();
}

.cpp (22): error C2512: 'Vehicle': no ​​appropriate default constructor available
Error executing cl.exe.
Reply

Use magic Report

0

Threads

12

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-5-11 08:00:01
| Show all posts
#include "stdafx.h"
#include <iostream>
using namespace std;
class Vehicle {
public:
Vehicle (double x)
{
cost = x;
}
Vehicle ()
{
cost = 0;
}
~ Vehicle () {}
virtual void show ()
{
cout << "I am a vehicle.";
}
virtual void costs ()
{
cout << "Cost is" << cost;
}
        private:
double cost;
};
class Car: public Vehicle {
public:
Car (double x)
{
cost = x;
}
~ Car () {}
void show ()
{
cout << "I am a car.";
}
void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
class Truck: public Vehicle {
public:
Truck (double x)
{
cost = x;
}
~ Truck () {}
void show ()
{
cout << "I am a truck.";
}
void costs ()
{
cout << "Cost is" << cost;
}
private:
double cost;
};
void callcost (Vehicle&);
int main ()
{
Vehicle vehi (1.5);
callcost (vehi);
Car c (3.8);
callcost (c);
Truck tr (5.8);
callcost (tr);
return 0;
}
void callcost (Vehicle&vehi)
{
vehi.show ();
vehi.costs ();
}
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-5-12 11:30:01
| Show all posts
Missing default constructor
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list