1

I have a class like this:

class Foo {
public:
    Foo();
private:
    SomethingProxy proxy;
    MyBar myBar;
};

In the constructor body (not initializer list), I want to do this:

Foo::Foo() {
    myBar.initializeProxy(proxy);
}

The code currently "works" for me, but is that guaranteed? Does the code invoke UB, or have any other problems?

These may not be relevant to the question, but here are some more details:

  • SomethingProxy's default constructor initializes it properly to the required state.
  • Having SomethingProxy and MyBar as members of Foo (as against pointers) is a business requirement, so initializeProxy() being virtual (or not) is not relevant here.
Masked Man
  • 1
  • 7
  • 40
  • 80

0 Answers0