By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Unnamed "Formal Parameter"

P: n/a
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


Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Mysooru" <na*******@yahoo.com> wrote in message
news:bf**********@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
Jul 19 '05 #2

P: n/a
Mysooru <na*******@yahoo.com> wrote in message
news:bf**********@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

Jul 19 '05 #3

P: n/a

Mysooru <na*******@yahoo.com> wrote in message
news:bf**********@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

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.