473,503 Members | 1,641 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(&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 1723
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
5197
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...
2
4585
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...
8
6645
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
15378
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
9397
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
2581
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
7801
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
2162
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...
24
2471
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...
0
7070
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...
0
7267
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,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
0
372
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...

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.