471,092 Members | 1,053 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

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(&wndclass, sizeof(WNDCLASS));

wndclass.style = style; /* Usually CS_HREDRAW | CS_VREDRAW */
wndclass.lpfnWndProc = proc;
wndclass.cbClsExtra = cbClsExtra; /* Usually 0 */
wndclass.cbWndExtra = cbWndExtra; /* Usually 0 */
wndclass.hInstance = NULL;
wndclass.hIcon = icon; /* Usually LoadIcon(0, IDI_APPLICATION) */
wndclass.hCursor = cursor; /* Usually LoadCursor(0, IDC_ARROW) */
wndclass.hbrBackground = background; /*
(HBRUSH)GetStockObject(WHITE_BRUSH) */
wndclass.lpszMenuName = menu_name; /* NULL or
MAKEINTRESOURCE(MENU_ID) */
wndclass.lpszClassName = class_name;

ATOM a = RegisterClass(&wndclass);

assert(a != 0);
}

HWND
MainWindow::create()
{
const char *application_name = "Test MyMFC"; /* Doubling as class
name. */

register_class(application_name, MainWindow::entry,
(HBRUSH)GetStockObject(WHITE_BRUSH));

g++ -Wall -W -ansi -pedantic -g -O0 -c MainWindow.cpp
MainWindow.cpp: In member function `HWND__* MainWindow::create()':
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 1569
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(&wndclass, sizeof(WNDCLASS));

wndclass.style = style; /* Usually CS_HREDRAW | CS_VREDRAW */
wndclass.lpfnWndProc = proc;
wndclass.cbClsExtra = cbClsExtra; /* Usually 0 */
wndclass.cbWndExtra = cbWndExtra; /* Usually 0 */
wndclass.hInstance = NULL;
wndclass.hIcon = icon; /* Usually LoadIcon(0, IDI_APPLICATION) */
wndclass.hCursor = cursor; /* Usually LoadCursor(0, IDC_ARROW) */
wndclass.hbrBackground = background; /*
(HBRUSH)GetStockObject(WHITE_BRUSH) */
wndclass.lpszMenuName = menu_name; /* NULL or
MAKEINTRESOURCE(MENU_ID) */
wndclass.lpszClassName = class_name;

ATOM a = RegisterClass(&wndclass);

assert(a != 0);
}

HWND
MainWindow::create()
{
const char *application_name = "Test MyMFC"; /* Doubling as class
name. */

register_class(application_name, MainWindow::entry,
(HBRUSH)GetStockObject(WHITE_BRUSH));

g++ -Wall -W -ansi -pedantic -g -O0 -c MainWindow.cpp
MainWindow.cpp: In member function `HWND__* MainWindow::create()':
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(&wndclass, sizeof(WNDCLASS));

wndclass.style = style; /* Usually CS_HREDRAW | CS_VREDRAW */
wndclass.lpfnWndProc = proc;
wndclass.cbClsExtra = cbClsExtra; /* Usually 0 */
wndclass.cbWndExtra = cbWndExtra; /* Usually 0 */
wndclass.hInstance = NULL;
wndclass.hIcon = icon; /* Usually LoadIcon(0, IDI_APPLICATION) */
wndclass.hCursor = cursor; /* Usually LoadCursor(0, IDC_ARROW) */
wndclass.hbrBackground = background; /*
(HBRUSH)GetStockObject(WHITE_BRUSH) */
wndclass.lpszMenuName = menu_name; /* NULL or
MAKEINTRESOURCE(MENU_ID) */
wndclass.lpszClassName = class_name;

ATOM a = RegisterClass(&wndclass);

assert(a != 0);
}

HWND
MainWindow::create()
{
const char *application_name = "Test MyMFC"; /* Doubling as class
name. */

register_class(application_name, MainWindow::entry,
(HBRUSH)GetStockObject(WHITE_BRUSH));

g++ -Wall -W -ansi -pedantic -g -O0 -c MainWindow.cpp
MainWindow.cpp: In member function `HWND__* MainWindow::create()':
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Paul Davis | last post: by
8 posts views Thread by Agent Mulder | last post: by
5 posts views Thread by Dave Vandervies | last post: by
5 posts views Thread by Gary Labowitz | last post: by
11 posts views Thread by The Directive | last post: by
12 posts views Thread by claudiu | last post: by

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.