By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,796 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Default arguments, one call compiles, the other does not

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

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.