#include <iostream>
#include <functional>
#include <vector>

class OtherThing{
public:
void addElement(std::function<int()> func){
    this->myfuncs.push_back(func);
}
void toggle(){
    std::cout << "toggle .. " << this->myfuncs[0]() << std::endl;
}
private:
std::vector<std::function<int()>> myfuncs; 
};

class Thing: public OtherThing{
public:
Thing(){
    std::function<int()> myfunc= [this]()->int{
        std::cout << "from lambda " << this->value << std::endl;
        return this->value;
        };
    this->addElement(myfunc);
    }
Thing(const Thing &src){
	value = src.value;
	std::function<int()> myfunc = [this]()->int{
		std::cout << "from copied lambda " << this->value << std::endl;
		return this->value;
	};
	this->addElement(myfunc);
}
void setValue(int value){
    this->value = value;
}
int getValue(){
    return this->value;
}
private:
int value;
};


int main() {
    // container for things 
    std::vector<Thing> mythings;
    
    // a thing
    Thing a;
    a.toggle();
    a.setValue(100);
    a.toggle();
    
    mythings.push_back(a);
    mythings[0].toggle();
    mythings[0].setValue(666);
    mythings[0].toggle();
    mythings[0].setValue(999);
    mythings[0].toggle();
    
    a.toggle();
    
    return 0;
}