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++ 48340 articles. 29 followers. Post

3 Replies
130 Views

Similar Articles

[PageSpeed] 35


  • 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 : ***********************************************************************************...

Formal parameter names are not required in function definitions. Why?!
This is valid C++ code, but invalid C code. *** int f(char*, int); int f(char*, int x) // note char* is not named. { return x; } *** C/C++ allows declarations without parameter names, but C requires that parameters of definitions are named. Why does C++ not have this behaviour? What value is added by allowing formal parameters in definitions not to be named? I initially thought that this was a hangover from C, where concievably, one might be doing inline assembly and therefore did not need the names of variables, only that one knows they are on the stack. Howeve...

p[] v.s. *p as formal parameters
Hello, Although there is obviously a difference between type p[n] and type *p when used to create non-parameter variables, I have always understood (possibly incorrectly) that they are identical in every way when used to declare formal parameters. Could someone please refer me to the section of the standard (I have the 1989 version) that proves my assumption one way or another? I have heard that some compilers don't consider formal parameter p to be a modifiable lvalue if declared as type p[n]. Thanks, Ray Mitchell On Mon, 31 May 2004 03:38:57 GMT, "Ray Mitch...

A question related to method formal parameters pass by reference
Hi, I am wondering if the following two cases are identical. I am confused. Thank you for your help. Case A: Person p = new Person(); Team t = new Team(p); //Print p.getName, get "Tom" <Team.java> public class Team { public Team(Person aPerson){ aPerson.setName("Tom"); } ... } </Team.java> Case B: Person p = null; Team t = new Team(p); //after constructing, p will refer to an object of Person with name of "Tom", am I right? //If I print p.getName, will I get "Tom" ? <Team.java> public class Team { public Team(Pers...

Access to generic formal parameters in an generic package instantiation
If G is a generic package and P is one of its formal parameters, it is legal to refer to G.P where G is visible? Does this depend on the kind of entity, or whether the formal part uses <>? Has anybody tried to use generic formal packages to emulate Standard ML signatures? Is it possible to express SML "where" constraints, that is, specify that two types in two formal packages are the same, without break down the formal packages to their components? It seems that generic formal packages are unusual because GNAT shows some strange effects (and the occasional bug box...

Problems passing the self.class var as a formal parameter
Hello, I my script I have a method call class ST_LTD_1 < Test::Unit::TestCase def test_st_ltd_1 xml_logger(self.class, string_to_search) end end this is the invoked method def xml_logger (test_id, vp_text) doc = Document.new xmldecl = XMLDecl.default doc.add(xmldecl) test_result = doc.add_element 'testresults' test_id = test_result.add_element 'testID' test_id.text = test_id if verify_result_1(vp_text) then pass = test_id.add_element 'pass' pass.text = 'PASS' else pass = test_id.add_element 'fail' pass.tex...

How to get generic formal parameter type into base class
Is there a way to get a generic formal parameter type into base class so that I can dispatch to a function with that type in the function signature? Below is what I am trying to achieve, and of course the main procedure will not compile. Thanks, package Classes is type Value_Type is range -2 ** 31 .. 2 ** 31 - 1; generic type Data_Type is (<>); package Translate_Base is type Xlate_Base_Type is abstract tagged record Value : Data_Type := Data_Type'first; end record; procedure Decode (Xlate_Class : in out Xlate_Base_Type; ...