472,958 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

default parameter with ...

Hi
The following code have a compile error:
printf_format.cpp: In function `void print(int, char*, ...)':
printf_format.cpp:6: invalid conversion from `const char*' to `int'
printf_format.cpp:6: invalid conversion from `int' to `char*'

I am using gcc 3.4, please HELP

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void print (int numberOfSpace=0,char *args="", ...){
print("numberOfSpace=%d\n",numberOfSpace);
}

int main(){
printf("asdad");
return 0;
}

thanks
from Peter (cm****@hotmail.com)

Mar 8 '06 #1
2 1913
cm****@hotmail.com wrote:
Hi
The following code have a compile error:
printf_format.cpp: In function `void print(int, char*, ...)':
printf_format.cpp:6: invalid conversion from `const char*' to `int'
printf_format.cpp:6: invalid conversion from `int' to `char*'

I am using gcc 3.4, please HELP

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void print (int numberOfSpace=0,char *args="", ...){
print("numberOfSpace=%d\n",numberOfSpace); ITYM `printf' on the line above, as opposed to `print'. }

int main(){
printf("asdad");
return 0;
}


I'll make no other comments (though there are certainly some to be
made). I'll leave it at the obvious typo.
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 8 '06 #2
cm****@hotmail.com wrote in news:1141790204.330131.278410
@e56g2000cwe.googlegroups.com:
Hi
The following code have a compile error:
printf_format.cpp: In function `void print(int, char*, ...)':
printf_format.cpp:6: invalid conversion from `const char*' to `int'
printf_format.cpp:6: invalid conversion from `int' to `char*'

I am using gcc 3.4, please HELP

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void print (int numberOfSpace=0,char *args="", ...){
print("numberOfSpace=%d\n",numberOfSpace);
}

int main(){
printf("asdad");
return 0;
}


gcc is right. The first parameter to your function is an int. You're
passing it a const char *. Recall that if you want to change what you're
passing for the 2nd parameter (and want the default value for the 1st),
you still must specify the 1st paramter (so you'd have to:
"print(0, "%s")"). Same idea goes for whatever parameters you're passing
through your ellipsis. In order for any values to go to the ellipsis,
you must specify the int and char* first.
Mar 8 '06 #3

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

Similar topics

26
by: Alex Panayotopoulos | last post by:
Hello all, Maybe I'm being foolish, but I just don't understand why the following code behaves as it does: - = - = - = - class listHolder: def __init__( self, myList= ): self.myList =...
18
by: Dan Cernat | last post by:
Hi there, A few threads I had a little chat about default values. I am starting this thread because I want to hear more opinions about the default values of function parameters. Some say they...
2
by: Ekim | last post by:
hy, I've got a question according default parameters of functions that are accessed from different files: ---- logging.h ---- void LogTrace(const char* errorLocation, const char* errorInfo =...
2
by: Vic Y | last post by:
Hi, I am trying to call a user defined function(UDF) from a stored proc, using a default parameter in the called UDF (e.g. @bid_price_type int = 0 ). However the calling stored proc complains...
2
by: The Plankmeister | last post by:
Hi... I have a query which I'm accessing through PHP as a stored procedure. However, I need to be able not to pass a couple of parameters in certain situations. When I do this, I get an error: ...
7
by: A.M | last post by:
Hi, Do we have default method parameter in C#? Something like this void method1(int i = 12) { .... }
8
by: cody | last post by:
Why doesn't C# allow default parameters for methods? An argument against I hear often is that the default parameters would have to be hardbaken into the assembly, but why? The Jit can take care of...
4
by: indigator | last post by:
I have an ASP.Net web service class, DataLayer.asmx.cs. I have two constructors for the DataLayer class. One is the default parameter-less one and the second one accepts a string argument. When I...
8
by: William Xu | last post by:
Compiling: template <class T = int> T foo(const T& t) {} int main(int argc, char *argv) {} gcc complains:
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.