Category : smart-pointers

I have a base product class with a few private members and a public getter that derived classes inherit. I would like to disqualify instantiation, since the class is intended for use with an abstract factory. I thought protected con/destructors might work, however, this breaks my smart pointers. Friending seems like a useful disaster. Is ..

Read more

I’m trying to use make_shared in my functional Parser library and I’m getting an error error: too many arguments to function ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& …) [with _Tp = parser::Parser, parser::state::empty>; _Args = {}]’ I suspect C++ is failing to infer my Parser constructor argument types since _Args = {} I tried to simplify my code and ..

Read more

There’s two issues with this code: Enabling shared from this on class B which is a derived class Calling shared_from_this() in the constructor of each class. class A : public std::enable_shared_from_this<A> { public: A() { shared_from_this(); } }; class B : public A, public std::enable_shared_from_this<B> { public: B() { shared_from_this(); } }; Is there to ..

Read more

Consider the following function: void example(void **ptr){ std::cout << *ptr << "n"; // pointer value std::cout << ptr << "n"; // pointer address std::cout << **reinterpret_cast<int**>(ptr); // value } The function signature cannot be changed. Is the following code valid, or should I use raw pointers? int main() { std::unique_ptr<int> x = std::make_unique<int>(20); std::cout << ..

Read more