#include <Arduino.h>
#include <vector>
class X {
public:
X(int val) : value(val) {}
void someFunction() const {
Serial.print("Value: ");
Serial.println(value);
// Modify this function as needed
}
void printValue() const {
Serial.print("Value: ");
Serial.println(value);
}
void addValue(int val) {
value += val;
printValue();
}
void subtractValue(int val) {
value -= val;
printValue();
}
int getValue() const {
return value;
}
private:
int value; // Added private member variable 'value'
};
void printValues(const X& a, const X& b) {
Serial.print("Object 'a' value: ");
Serial.println(a.getValue());
Serial.print("Object 'b' value: ");
Serial.println(b.getValue());
}
void setup() {
Serial.begin(9600); // Initialize serial communication
// Create two objects of class X
X a(10);
X b(20);
// Create a vector of X objects
std::vector<X> objects;
// Add objects to the vector using push_back
objects.push_back(a);
objects.push_back(b);
// Perform operations on the objects
for (const X& obj : objects) {
obj.someFunction(); // Assuming someFunction does not modify the object
}
// Add 5 to the value of object 'a'
a.addValue(5);
// Subtract 3 from the value of object 'b'
b.subtractValue(3);
// Print updated values
Serial.println("After operations:");
printValues(a, b);
}
void loop() {
// Your main code here
}