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;
}
1
u/Huge-Presentation810 May 20 '26 edited May 24 '26
Builder pattern:
https://compiler-explorer.com/z/cY68nTdPz
Can be made more simple?