473,657 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default arguments, one call compiles, the other does not

This complete program compiles just fine:
void foo(int, int = 0);

void foo(int a, int b)
{
(void)a;
(void)b;
}

int
main()
{
foo4711);
}

However, this part of the *real* program does not:
void register_window _class(const char *class_name,
WNDPROC proc,
HBRUSH background,
const char * = NULL,
HICON = LoadIcon(0, IDI_APPLICATION ),
HCURSOR = LoadCursor(0, IDC_ARROW),
UINT = CS_HREDRAW | CS_VREDRAW,
int = 0,
int = 0);

void register_class( const char *class_name,
WNDPROC proc,
HBRUSH background,
const char *menu_name,
HICON icon,
HCURSOR cursor,
UINT style,
int cbWndExtra,
int cbClsExtra)
{
WNDCLASS wndclass;

ZeroMemory(&wnd class, sizeof(WNDCLASS ));

wndclass.style = style; /* Usually CS_HREDRAW | CS_VREDRAW */
wndclass.lpfnWn dProc = proc;
wndclass.cbClsE xtra = cbClsExtra; /* Usually 0 */
wndclass.cbWndE xtra = cbWndExtra; /* Usually 0 */
wndclass.hInsta nce = NULL;
wndclass.hIcon = icon; /* Usually LoadIcon(0, IDI_APPLICATION ) */
wndclass.hCurso r = cursor; /* Usually LoadCursor(0, IDC_ARROW) */
wndclass.hbrBac kground = background; /*
(HBRUSH)GetStoc kObject(WHITE_B RUSH) */
wndclass.lpszMe nuName = menu_name; /* NULL or
MAKEINTRESOURCE (MENU_ID) */
wndclass.lpszCl assName = class_name;

ATOM a = RegisterClass(& wndclass);

assert(a != 0);
}

HWND
MainWindow::cre ate()
{
const char *application_na me = "Test MyMFC"; /* Doubling as class
name. */

register_class( application_nam e, MainWindow::ent ry,
(HBRUSH)GetStoc kObject(WHITE_B RUSH));

g++ -Wall -W -ansi -pedantic -g -O0 -c MainWindow.cpp
MainWindow.cpp: In member function `HWND__* MainWindow::cre ate()':
MainWindow.cpp: 22: error: too few arguments to function `void
register_class( const char*, LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM),
HBRUSH__*, const char*, HICON__*, HICON__*, UINT, int, int)'
MainWindow.cpp: 48: error: at this point in file

Line 48 is the call to register_class. ..how do I make it compile while
keeping my default arguments? Sorry for posting an incomplete snippet
filled to the brim with platform specific code, but what was supposed
to be my exhibition program failed to exhibit the problem I need help
solving. =/

/ E

Jul 6 '06 #1
2 1737
Eric Lilja wrote:
This complete program compiles just fine:
void foo(int, int = 0);

void foo(int a, int b)
{
(void)a;
(void)b;
}

int
main()
{
foo4711);
}

However, this part of the *real* program does not:
void register_window _class(const char *class_name,
WNDPROC proc,
HBRUSH background,
const char * = NULL,
HICON = LoadIcon(0, IDI_APPLICATION ),
HCURSOR = LoadCursor(0, IDC_ARROW),
UINT = CS_HREDRAW | CS_VREDRAW,
int = 0,
int = 0);

void register_class( const char *class_name,
WNDPROC proc,
HBRUSH background,
const char *menu_name,
HICON icon,
HCURSOR cursor,
UINT style,
int cbWndExtra,
int cbClsExtra)
{
WNDCLASS wndclass;

ZeroMemory(&wnd class, sizeof(WNDCLASS ));

wndclass.style = style; /* Usually CS_HREDRAW | CS_VREDRAW */
wndclass.lpfnWn dProc = proc;
wndclass.cbClsE xtra = cbClsExtra; /* Usually 0 */
wndclass.cbWndE xtra = cbWndExtra; /* Usually 0 */
wndclass.hInsta nce = NULL;
wndclass.hIcon = icon; /* Usually LoadIcon(0, IDI_APPLICATION ) */
wndclass.hCurso r = cursor; /* Usually LoadCursor(0, IDC_ARROW) */
wndclass.hbrBac kground = background; /*
(HBRUSH)GetStoc kObject(WHITE_B RUSH) */
wndclass.lpszMe nuName = menu_name; /* NULL or
MAKEINTRESOURCE (MENU_ID) */
wndclass.lpszCl assName = class_name;

ATOM a = RegisterClass(& wndclass);

assert(a != 0);
}

HWND
MainWindow::cre ate()
{
const char *application_na me = "Test MyMFC"; /* Doubling as class
name. */

register_class( application_nam e, MainWindow::ent ry,
(HBRUSH)GetStoc kObject(WHITE_B RUSH));

g++ -Wall -W -ansi -pedantic -g -O0 -c MainWindow.cpp
MainWindow.cpp: In member function `HWND__* MainWindow::cre ate()':
MainWindow.cpp: 22: error: too few arguments to function `void
register_class( const char*, LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM),
HBRUSH__*, const char*, HICON__*, HICON__*, UINT, int, int)'
MainWindow.cpp: 48: error: at this point in file

Line 48 is the call to register_class. ..how do I make it compile while
keeping my default arguments? Sorry for posting an incomplete snippet
filled to the brim with platform specific code, but what was supposed
to be my exhibition program failed to exhibit the problem I need help
solving. =/
Take a look at the forward declaration of register_window _class, and
then the actual declaration of register_class. Hint:
register_window _class is not register_class. register_class has no
default params.

Jul 6 '06 #2

red floyd wrote:
Eric Lilja wrote:
This complete program compiles just fine:
void foo(int, int = 0);

void foo(int a, int b)
{
(void)a;
(void)b;
}

int
main()
{
foo4711);
}

However, this part of the *real* program does not:
void register_window _class(const char *class_name,
WNDPROC proc,
HBRUSH background,
const char * = NULL,
HICON = LoadIcon(0, IDI_APPLICATION ),
HCURSOR = LoadCursor(0, IDC_ARROW),
UINT = CS_HREDRAW | CS_VREDRAW,
int = 0,
int = 0);

void register_class( const char *class_name,
WNDPROC proc,
HBRUSH background,
const char *menu_name,
HICON icon,
HCURSOR cursor,
UINT style,
int cbWndExtra,
int cbClsExtra)
{
WNDCLASS wndclass;

ZeroMemory(&wnd class, sizeof(WNDCLASS ));

wndclass.style = style; /* Usually CS_HREDRAW | CS_VREDRAW */
wndclass.lpfnWn dProc = proc;
wndclass.cbClsE xtra = cbClsExtra; /* Usually 0 */
wndclass.cbWndE xtra = cbWndExtra; /* Usually 0 */
wndclass.hInsta nce = NULL;
wndclass.hIcon = icon; /* Usually LoadIcon(0, IDI_APPLICATION ) */
wndclass.hCurso r = cursor; /* Usually LoadCursor(0, IDC_ARROW) */
wndclass.hbrBac kground = background; /*
(HBRUSH)GetStoc kObject(WHITE_B RUSH) */
wndclass.lpszMe nuName = menu_name; /* NULL or
MAKEINTRESOURCE (MENU_ID) */
wndclass.lpszCl assName = class_name;

ATOM a = RegisterClass(& wndclass);

assert(a != 0);
}

HWND
MainWindow::cre ate()
{
const char *application_na me = "Test MyMFC"; /* Doubling as class
name. */

register_class( application_nam e, MainWindow::ent ry,
(HBRUSH)GetStoc kObject(WHITE_B RUSH));

g++ -Wall -W -ansi -pedantic -g -O0 -c MainWindow.cpp
MainWindow.cpp: In member function `HWND__* MainWindow::cre ate()':
MainWindow.cpp: 22: error: too few arguments to function `void
register_class( const char*, LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM),
HBRUSH__*, const char*, HICON__*, HICON__*, UINT, int, int)'
MainWindow.cpp: 48: error: at this point in file

Line 48 is the call to register_class. ..how do I make it compile while
keeping my default arguments? Sorry for posting an incomplete snippet
filled to the brim with platform specific code, but what was supposed
to be my exhibition program failed to exhibit the problem I need help
solving. =/
Take a look at the forward declaration of register_window _class, and
then the actual declaration of register_class. Hint:
register_window _class is not register_class. register_class has no
default params.
LOL! I must be blind not seeing that! Thanks for the quick response,
now everything works just fine.

/ E

Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
5253
by: Edward Diener | last post by:
In the tutorial on functions there are sections on default arguments and keyword arguments, yet I don't see the syntactic difference between them. For default arguments the tutorial shows: def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): while for keyword arguments the tutorial shows: def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
2
4593
by: Paul Davis | last post by:
I've just converted from gcc2.96 to gcc3.3. One of the things that 3.3 complained about was my use of functions which had default arguments. Previously, I put the defaults in my function definition, and then copied the definition directly as the declaration: void A::foo(int a, int b=0); // declare somewhere void A::foo(int a, int b=0) {...} // define in another file 3.3 doesn't like this, because the default is repeated twice. I...
8
6656
by: Agent Mulder | last post by:
Hi group, I want to know why this doesn't work void f(int a=0,int b=1,int c=2){} int main() { f(); //OK f(1); //OK f(1,2); //OK f(1,2,3); //OK
5
15388
by: Dave Vandervies | last post by:
If I feed this to g++: -------- int foo(int i=42); int foo(int i=42) { return i; } -------- It says (with -W -Wall -ansi -pedantic):
5
9403
by: Gary Labowitz | last post by:
Is it permissable to place default arguments in the definition of a constructor rather than in the declaration. Following extract: class X { public: X(int arg1, int arg2); .... }
11
2603
by: The Directive | last post by:
This code will not compiled: In main function: Dot temp = new Dot( *(new Point( 5, 5 )) ); In Dot class: //Constructor with default arguments. Dot::Dot( Point& point= *(new Point( 5, 5 )),
12
7849
by: claudiu | last post by:
Hi, I'll go straight to the first question. Why does the code below compile? void f(int i = 0); int main() { (&f)();
35
2218
by: bukzor | last post by:
I've found some bizzare behavior when using mutable values (lists, dicts, etc) as the default argument of a function. I want to get the community's feedback on this. It's easiest to explain with code. This example is trivial and has design issues, but it demonstrates a problem I've seen in production systems: def main(argv = ): 'print out arguments with BEGIN and END' argv.insert(1, "BEGIN")
24
2506
by: Steven D'Aprano | last post by:
Sometimes it seems that barely a day goes by without some newbie, or not- so-newbie, getting confused by the behaviour of functions with mutable default arguments. No sooner does one thread finally, and painfully, fade away than another one starts up. I suggest that Python should raise warnings.RuntimeWarning (or similar?) when a function is defined with a default argument consisting of a list, dict or set. (This is not meant as an...
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.