I am writing a new application and want to start getting into C++ 11.
I have 2 questions:
Q1:
Should i not be using * nowadays?
I can see that the unique_ptr<Type> varName( new Type() ) seems to be preferred?
Q2:
If the above is true, is something like this correct:
h:
class App : public BaseClass
{
    // Methods
public:
    App();
    ~App();
private:
    // Properties
public:
    unique_ptr<WindowInfo> GetMainWindowInfo() const;
    void SetMainWindowInfo( unique_ptr<WindowInfo> windowInfo );
private:
    unique_ptr<WindowInfo> mainWindowInfo;
};
cpp:
App::App()
{
    // Set up the main app window
    unique_ptr<WindowInfo> windowInfo( new WindowInfo() );
    windowInfo->SetTitle( L"Blah" );
    windowInfo->SetHeight( CW_USEDEFAULT );
    windowInfo->SetWidth( CW_USEDEFAULT );
    this->SetMainWindowInfo( windowInfo );
}
App::~App()
{  
    // Probs don't need this anymore right?
    delete this->mainWindowInfo;
    this->mainWindowInfo = nullptr;
}
unique_ptr<WindowInfo> App::GetMainWindowInfo() const
{
    return this->mainWindowInfo;
}
void App::SetMainWindowInfo( unique_ptr<WindowInfo> windowInfo )
{
    this->mainWindowInfo = windowInfo;
}
The user of App is that it will be a way of getting all that information about my main window, thus it could be used throughout my application...
Aucun commentaire:
Enregistrer un commentaire