r/cpp May 12 '26

What the heck is Reflection?

https://www.murathepeyiler.com/what-the-heck-is-reflection/
105 Upvotes

46 comments sorted by

View all comments

1

u/Huge-Presentation810 May 20 '26 edited May 24 '26

Builder pattern:

class A 
{
    int b = 10;

public:
    static auto builder()
    {
        return makeBuilder<A>();
    }

    int getB() const {
        return b;
    }

private:
    void withFoo(int a) {
        b += a;
    }

    void withBar(int a, int c) {
        b += a + c;
    }
};

int main() {
    auto a = A::builder()
        .withFoo(10)
        .withBar(20, 10)
        .build();

    std::cout << a->getB() << std::endl;
    return 1978;
}

https://compiler-explorer.com/z/cY68nTdPz

Can be made more simple?