In below code I'm having C2248 error. When I replace smart pointers with the raw pointers it compiles. However I want to use smart pointer std::shared_ptr<> object. How can I correct this error when using smart pointer?
#include <iostream>
#include <string>
#include <memory>
class GameSetting{
inline static std::shared_ptr<GameSetting> _instance;
unsigned int _brightness;
unsigned int _width;
unsigned int _heigth;
GameSetting():_brightness{150}, _width{300}, _heigth{200}
{}
public:
static std::shared_ptr<GameSetting> getInstance(){
if(! _instance)
_instance=std::make_shared<GameSetting>();
return _instance;
}
void setBrightness(unsigned brightness){_brightness=brightness;}
void setWidth(unsigned int width){_width=width;}
void setHeight(unsigned int height){_heigth=height;}
unsigned int getBrightness()const{return _brightness;}
unsigned int getWidth()const{return _width;}
unsigned int getHeigth()const{return _heigth;}
void displaySettings()const{
std::cout<<"brigthness: "<<_brightness<<'\n'<<"width: "<<_width
<<'\n'<<"heigth: "<<_heigth<<"\n\n";
}
};
int main()
{
std::shared_ptr<GameSetting> setting=GameSetting::getInstance();
setting->displaySettings();
}