Unnamed "Formal Parameter"

  • Permalink
  • submit to reddit
  • Email
  • Follow


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




0
Reply nags_bhel (3) 7/24/2003 5:24:29 AM

See related articles to this posting

"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


0
Reply john_andronicus (3950) 7/24/2003 5:26:28 AM


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



0
Reply no4133 (566) 7/24/2003 5:27:22 AM

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
>
>
>
>


0
Reply mkwahler (3821) 7/24/2003 6:11:33 AM
comp.lang.c++ 48148 articles. 26 followers. Post

3 Replies
103 Views

Similar Articles

[PageSpeed] 32


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

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 "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 &g...

redefinition of formal parameter
Howdy all, I am attempting to write a try.throw.catch block, and I have to logic of it down, but I am hitting a syntax snag with my char *: in my driver: void test(int x, int y) { if (x >= y) throw errorHandle("smaller was larger than bigger"); } in class "errorHandle": //constructor errorHandle(char *x) { exception(x); } and i get: Redifinition of formal parameter 'x'; any clues? [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On 26 Sep 2005 04:27:...

Commented out formal parameter?
I've got some legacy code I'm maintaining. There's a method declared in the class.h file like this: void foo(unsigned priority); and it's implemented as: void myClass::foo (unsigned /* priority */) { // body omitted } The parameter priority isn't actually used anywhere in the body (I can only assume it was at one point in the history of the code). What I don't understand is how this compiles (and compile it does, under 5 different compilers). What does the compiler think the signature of the method is? "Roy Smith" <roy@panix.com> wrote in ...

Passing the same actual as both in and out formal parameters?
Consider: type T is tagged private; procedure P (A : in T; B : out T) is separate; Object : T; begin P (A => Object, B => Object); This seems legal but I suspect the execution might lead to bugs if P reads and writes components of A and B in arbitrary order, e.g. type T is tagged record L, M : Integer; end record; procedure P (A : in T; B : out T) is begin B.L := A.M; -- does this change A.L too? B.M := A.L; -- bug: A.L has been clobbered, now B.M = B.L? end P; My concern stems from the fact that T is tagged (I cannot change that), so Objec...

Arbitrary number of formal parameters
Hi there, Is it possible in Java to write a method, which allows an arbitrary number of formal parameters? I know it is possible in C# although I forgot the syntax. So far, in Java I've only seen passing of a Collection or Map of Arguments. Martin wrote: > Hi there, > > Is it possible in Java to write a method, which allows an arbitrary > number of formal parameters? Yes. http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html -- Andrea Francia http://www.andreafrancia.it/ Martin wrote: > Hi there, > > Is it possible in Java to write a method, which a...

default formal parameters in generic declarations
I've spent some time reading ARM2005/12. Generic Units. Formal objects and subprograms can have default values. Formal types and packages cannot. Could someone point me to the discussion where this inconsistency was decided to be a good thing? I have a certain sympathy with this absence with regard to packages, because Ada as yet has no expression for partial specification of packages, package derivation other than child packages, or (consequentially) a declaration "abstract package". The same, however, does not hold for types, not in the least. I have a couple of use cases...

Difference between char [ ] and char * as formal parameters
Is there any difference between the following function prototypes? void func(int arr [ ]); and void func(int *ptr); When I print the address of arr and ptr, they reflect the same value (address of the array). I can even say arr++ and ptr++ without any problem. So, is there any difference between the two? Bintom * bintom, on 27.06.2010 19:11: > Is there any difference between the following function prototypes? > > void func(int arr [ ]); > > and > > void func(int *ptr); > > When I print the address of arr and ptr, they r...

Formal parameters and arguments object sharing
"Inspired" by Chrome's bug with sharing formal parameters and corresponding `arguments' object indexes. Here's an abstract (and correct, according to spec) description of how (and which) `arguments' indexes should be linked with corresponding formal parameters, what's happening when we delete arguments[n], etc. http://gist.github.com/539974 Chrome's bug: http://code.google.com/p/chromium/issues/detail?id=52484 P.S.: I remember old similar discussion (whether Chrome wrong or not) -- http://groups.google.ru/group/comp.lang.javascript/browse_thread/threa...

Get formal parameter names of a method?
Is there a way to reflect on a method to get the declard names of the parameters? class Equipment def install(tool, packaging) end end I can do this: m = Equipment.new.method(:install) m.arity # => 2 I want to somehow find out that the client code has declared the parameters named 'tool' and 'packaging'. Is this possible somehow? I feel like it should be, but I can't quite figure it out. Thanks! Jeff -- Posted via http://www.ruby-forum.com/. Jeff Cohen wrote: > Is there a way to reflect on a method to get the declard names of the > parameters? &...

lambda expression's formal parameter
Hello schemers, I wrote a programm to define the built-in procedure cadr myself, named my-cadr **************************************************************************************** (define compose (lambda (p1 p2) (lambda x (p1 (p2 x))))) (define my-cadr (compose car cdr)) (my-cadr '(a b c)) **************************************************************************************** yes, in the compose, i missed the parentheses in the lambda expression's formal parameter the correct one is : ***********************************************************************************...