function.h
#include”members.h”
#include<iostream>
using namespace std;
Car::Car(double w, double s)
{
weight = w;
speed = s;
}
Car::Car (const Car &p)
{
weight = p.weight;
speed = p.speed;
}
void Car::print()
{
cout<< “重量为” << weight << endl;
cout<< “速度为” << speed << endl;
}
main.cpp
#include”members.h”
#include”function.h”
#include<iostream>
using namespace std;
int main()
{
Car car_3(1000.23, 3000.4);
car_3.print();
Car car_1(100.1, 100.3);
Car car_2(car_1);
car_1.print();
return 0;
}
members.h
// 类的定义
// 定义数据和成员函数
#ifndef COMPLEX_H_
#define COMPLEX_H_
#include<iostream>
using namespace std;
class Car
{
private:
double weight;
double speed;
public:
Car (double, double);
Car (const Car &p);
void print();
};
#endif
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/270673.html