Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Unnamed "Formal Parameter" (http://www.velocityreviews.com/forums/t275988-unnamed-formal-parameter.html)

Mysooru 07-24-2003 05:24 AM

Unnamed "Formal Parameter"
 
Hi All,


One of the ATL class.....

template <class Base>
class CComObject : public Base
{
public:
typedef Base _BaseClass;
CComObject(void* = NULL)
{
..............
}
:
:
};

Constructor takes parameter "void* = NULL",
how this unnamed parameter to the constructor is used

Thanks and Regards
HoRaNa





John Harrison 07-24-2003 05:26 AM

Re: Unnamed "Formal Parameter"
 

"Mysooru" <nags_bhel@yahoo.com> wrote in message
news:bfnpp5$9lu$1@news.mch.sbs.de...
> Hi All,
>
>
> One of the ATL class.....
>
> template <class Base>
> class CComObject : public Base
> {
> public:
> typedef Base _BaseClass;
> CComObject(void* = NULL)
> {
> ..............
> }
> :
> :
> };
>
> Constructor takes parameter "void* = NULL",
> how this unnamed parameter to the constructor is used
>
> Thanks and Regards
> HoRaNa
>


It's not. The parameter is there so that CComObject is compatible with other
classes such as CComPolyObject. Both CComObject, CComPolyObject and others
might be used as parameters to the template CComCreator which assumes that a
constructir which takes one parameter exists.

For instance

class A
{
public:
A(void* = 0) {} // unused parameter
};

class B
{
public:
B(void* p) : pp(p) {} // used parameter
private:
void* pp;
};

template <class T>
class C
{
public:
static T* create(void* p = 0) { return new T(p); }
};

int main()
{
A* a = C<A>::create();
B* b = C<B>::create("hello");
}

C<A>::create would not compile unless A::A had a parameter even though it is
not used.

john



David White 07-24-2003 05:27 AM

Re: Unnamed "Formal Parameter"
 
Mysooru <nags_bhel@yahoo.com> wrote in message
news:bfnpp5$9lu$1@news.mch.sbs.de...
> Hi All,
>
>
> One of the ATL class.....
>
> template <class Base>
> class CComObject : public Base
> {
> public:
> typedef Base _BaseClass;
> CComObject(void* = NULL)
> {
> ..............
> }
> :
> :
> };
>
> Constructor takes parameter "void* = NULL",
> how this unnamed parameter to the constructor is used


It isn't used. Maybe the designers included the pointer for possible use in
a future version that would not require existing code being re-compiled.

DW




Mike Wahler 07-24-2003 06:11 AM

Re: Unnamed "Formal Parameter"
 

Mysooru <nags_bhel@yahoo.com> wrote in message
news:bfnpp5$9lu$1@news.mch.sbs.de...
> Hi All,
>
>
> One of the ATL class.....
>
> template <class Base>
> class CComObject : public Base
> {
> public:
> typedef Base _BaseClass;
> CComObject(void* = NULL)
> {
> ..............
> }
> :
> :
> };
>
> Constructor takes parameter "void* = NULL",
> how this unnamed parameter to the constructor is used
>
> Thanks and Regards
> HoRaNa
>
>
>
>





All times are GMT. The time now is 03:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.