Suppose I have a class
class MyClass
int buf[10];
public:
MyClass(int i) {
new (&buf) OtherClass(i); // How to move this to constructor initialize list?
}
Simply copy that line to the place after :
not working.
I'm not sure how you would use the constructed object; I suppose MyClass
has a data member pointer to the object, then initialize the pointer like:
class MyClass {
int buf[10];
OtherClass* p;
public:
MyClass(int i) : p(new (&buf) OtherClass(i)) {
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With