TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25737 5
Delegating Constructors

Delegating constructors allow the default constructor of a class to call the parameterized constructor by default.

This is somewhat unintuitive, but has a lot of applications in frameworks that generate components dynamically down inside their operation, but cannot take the arguments at that managerial level.

class SpecialWindow : public Gtk::Window {
public:

// 1. Parameterized Constructor
SpecialWindow(std::string inst_name, int inst_val)
: name(inst_name), val(inst_val) { // ... }

// default /w delegating constructor
SpecialWindow() : SpecialWindow("item 1", 100)
{ //... }

};


int main() {

auto app = Gtk::Application::create("org.gtkmm.examples.base");

return app->make_window_and_run<SpecialWindow>(argc, argv);
}

I guess "everybody knew" that already, but I didn't.

https://redd.it/1wssxsq
@r_cpp
Reddit From the cpp community on Reddit Explore this post and more from the cpp community
More from @r_cpp
  1. Oct 3, 2026You should think about recompiling your C++ programs with GCC 16 and C++26, because it zer…
  2. Oct 3, 2026Teodorescu - [https://youtu.be/vVFFW6hoG1Y](https://youtu.be/vVFFW6hoG1Y) * Demystifying C…
  3. Oct 3, 2026New C++ Conference Videos Released This Month - September 2026 (Updated To Include Videos…
  4. Oct 3, 2026HPX 2.0.0 RC1 Released! – The HPX Project HPX is a general-purpose parallel C++ runtime sy…
  5. Oct 3, 2026[PLDI'26] Persistent Iterators with Value Semantics https://www.youtube.com/watch?v=cq33C5…
  6. Oct 3, 2026A Cross-Toolkit Timeline Control, Wed, Oct 14, 2026, 6:00 PM https://www.meetup.com/utah-c…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →