RE: [Dev-C++] In constructor parameter list x = null
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2003-03-31 16:20:32
|
No, not defensive programming.
It's a default parameter value, if the parameter isn't sent in when
making the call, i.e. a function like
int sum(int a = 1, b = 2, c = 3) {
return a+b+c;
}
may be called as:
printf("%d\n",sum()); // will print 6 (1+2+3)
printf("%d\n",sum(5)); // will print 10 (5+2+3)
printf("%d\n",sum(5,4)); // will print 12 (5+4+3)
printf("%d\n",sum(5,4,7)); // will print 16 (5,4,7)
Observe, that it's only the rightmost n parameters that may be ignored
when calling a function taking default parameters. The following isn't
allowed:
int foobar(void *p = NULL, const char *s);
since there exists a parameter WITHOUT a default value AFTER a parameter
WITH a default parameter.
/Per W
On Mon, 31 Mar 2003, Somanathan Kaimal wrote:
> Hi,
>
> Its assigning a default value NULL to pParent. If you call this proc with a
> valid pointer it will override this value. This is for error checking
> (Defensive programming).
>
> Somanathan
>
> -----Original Message-----
> From: Daniel Glenfield [mailto:sp...@ho...]
> Sent: Monday, March 31, 2003 6:30 PM
> To: dev...@li...
> Subject: [Dev-C++] In constructor parameter list x = null
>
> Can someone explain this to me? It's in a header file for a class
> declaration, for the only constructor of the class.
>
> CPenWidthsDlg(CWnd* pParent = NULL);
>
> It's derived from CDialog so I assume that's got something to do with it. I
> am just confused why the parameter is assigned a NULL value. If I pass in a
> pointer will it just get assigned to NULL? then what's the point? To save me
>
> from having to assign it to NULL in the constructor body or something?
>
>
>
>
>
> _________________________________________________________________
> Get Hotmail on your mobile phone
> http://www.msn.co.uk/msnmobile/mobilehotmail
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: ValueWeb:
> Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
> No other company gives more support or power for your dedicated server
> http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|