King
King

Reputation: 51

Does this constructor return a instance?

virtual BOOL Create( 
    LPCTSTR lpszCaption, 
    DWORD dwStyle, 
    const RECT& rect,  //we need to pass a RECT instance
    CWnd* pParentWnd, 
    UINT nID  
);

// Create a push button.
myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 
CRect(10,10,100,30), pParentWnd, 1);

CRect(10,10,100,30) is a constructor,does this mean the constructor return a instance?

Upvotes: 0

Views: 62

Answers (2)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10425

//CRect(10,10,100,30) is a constructor...

No it is not. It is the declaration of an object. It does call the constructor but the object is created locally, not returned by the constructor.

Upvotes: 1

lcs
lcs

Reputation: 4255

This code is equivalent to the following :

CRect rect = CRect(10,10,100,30);

// Create a push button.
myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 
rect, pParentWnd, 1);

The constructor returns an instance of the class it is constructed, which is used by the Create function.

Upvotes: 0

Related Questions