-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_tiny_func.cpp
More file actions
70 lines (53 loc) · 1.45 KB
/
lambda_tiny_func.cpp
File metadata and controls
70 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by zing on 6/30/2020.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Vehicle {
private:
string m_vehicleType;
int m_totalOfWheel;
public:
Vehicle(const string &type, int wheel);
Vehicle();
~Vehicle();
string GetType() const { return m_vehicleType; }
int GetNumOfWheel() const { return m_totalOfWheel; }
};
// Constructor with default value for
// m_vehicleType and m_totalOfWheel
Vehicle::Vehicle() : m_totalOfWheel(0) {
}
// Constructor with user-defined value for
// m_vehicleType and m_totalOfWheel
Vehicle::Vehicle(
const string &type,
int wheel) :
m_vehicleType(type),
m_totalOfWheel(wheel) {
}
// Destructor
Vehicle::~Vehicle() {
}
auto main() -> int {
cout << "[lambda_tiny_func.cpp]" << endl;
// Initializing several Vehicle instances
Vehicle car("car", 4);
Vehicle motorcycle("motorcycle", 2);
Vehicle bicycle("bicycle", 2);
Vehicle bus("bus", 6);
// Assigning the preceding Vehicle instances to a vector
vector<Vehicle> vehicles = {car, motorcycle, bicycle, bus};
// Displaying the elements of the vector
// using Lambda expression
cout << "All vehicles:" << endl;
for_each(
begin(vehicles),
end(vehicles),
[](const Vehicle &vehicle) {
cout << vehicle.GetType() << " " << vehicle.GetNumOfWheel() << endl;
});
return 0;
}