Unnamed "Formal Parameter"

Discussion in 'C++' started by Mysooru, Jul 24, 2003.

  1. Mysooru

    Mysooru Guest

    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
     
    Mysooru, Jul 24, 2003
    #1
    1. Advertising

  2. "Mysooru" <> wrote in message
    news:bfnpp5$9lu$...
    > 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
     
    John Harrison, Jul 24, 2003
    #2
    1. Advertising

  3. Mysooru

    David White Guest

    Mysooru <> wrote in message
    news:bfnpp5$9lu$...
    > 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
     
    David White, Jul 24, 2003
    #3
  4. Mysooru

    Mike Wahler Guest

    Mysooru <> wrote in message
    news:bfnpp5$9lu$...
    > 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
    >
    >
    >
    >
     
    Mike Wahler, Jul 24, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mattia Belletti

    unnamed object creation

    Mattia Belletti, Oct 20, 2003, in forum: Java
    Replies:
    4
    Views:
    439
    Jason Us
    Oct 22, 2003
  2. Razmig K
    Replies:
    3
    Views:
    726
    John L Fjellstad
    Sep 5, 2003
  3. Roy Smith

    Commented out formal parameter?

    Roy Smith, Nov 21, 2005, in forum: C++
    Replies:
    5
    Views:
    315
    Kaz Kylheku
    Nov 21, 2005
  4. aidy
    Replies:
    2
    Views:
    91
    Kenosis
    Jun 20, 2006
  5. Jeff Cohen
    Replies:
    6
    Views:
    155
Loading...

Share This Page