[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ProgSoc] C++ and default values



Hi.

I don't know the ins and outs of C++, but I have to run my eyes over some C++ 
code (targeted for a Windows C++ compiler, probably Visual C++).

In Foo.cpp, the code has a method:

  void Foo::Bar(DWORD dw1, double d2)
  {
    ...
  }

and sometimes it's invoked:

  Bar(42, 1.00f);

but other time's it's invoked:

  Bar(42);

I cannot see anywhere that the last parameter has a default value assigned to 
it.  I have a copy of Foo.h, but I believe it may be out of date (and it is 
not easy for me to obtain an up-to-date copy).  It doesn't have any 
references to a default value.

Should the method in Foo.cpp have some detail about a default value in the 
signature?  Or is it only required in the prototype in the header file?  From 
[Stroustrup 1987 p121] it has the example:

  extern char* hex(long, int =0);

... but that's _all_ it says.  It doesn't talk about when you actually define 
the implementation of that method whether you have to indicate the default 
value again.

I don't need this code to compile, I just need to understand if it would 
compile.  :-)

Correct answers, pointers and general arm waving appreciated.

Thanks.

Greg.


Stroustrup, B. (1977), The C++ Programming Language
Addison-Wesley

-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.