Category : oop

This does not compile: struct Base { void something( int a ) { } }; struct Derived : public Base { static void something() { std::unique_ptr<Derived> pointer = std::make_unique<Derived>(); pointer->something( 11 ); } }; It’s possible to fix with using Base::something but still, is it possible to make inheritance work as advertised even inside methods? ..

Read more

I have a non-void function which returns a value to be used as an input of a class constructor, but there is a possibility for that value not to be available, so I want to return the value in case of success or just terminate (std::terminate()) the application in case of failure before the function ..

Read more

I have following classes: class ATemperatureDevice{}; class AHumidityDevice{}; class BluetoothLeDevice{}; class Sensor1 : BluetoothLeDevice, ATemperatureDevice, AHumidityDevice {}; class Sensor2 : BluetoothLeDevice, AHumidityDevice {}; I have a vector<BluetoothLeDevice>, where all devices are stored. The Classes ATemperatureDevice, AHumidityDevice and BluetoothLeDevice have virtual functions. When I pick one, I have a BluetoothLeDevice. Now I want to check if ..

Read more

For example there are classes A and B. A uses B’s methods and vice versa. So what is usually done passing pointer to other class in constructor. But what if they use each other – how should I pass B to A if B not yet constructed? Ok, I wrote setter for A and call ..

Read more

I have a header create.h file with the Hero class, there is also a function createHero()(in main.cpp) that creates an object of the Hero class, this function is called when the condition is met, at this point the created object from the createHero() function is returned, however this object is local and I cannot access ..

Read more