Help with default arguments in C++

From: Zac Bond (zwb2_at_cwru.edu)
Date: 02/29/04


Date: Sun, 29 Feb 2004 03:27:15 -0500

The following function was the only way I could think of to initialize
a standard string based on a simple list of characters:

string Solver::createstr(char c1, char c2 = 0, char c3 = 0, char c4 =
0)
{
   char cstr[5] = {c1, c2, c3, c4, 0};
   string new_string = cstr;
   return new_string;
}

So why does
ttp.nolst = createstr(tline[0], tline[1], tline[2], tline[3]);

work perfectly fine (nolst is a string inside class ttp), while the
following
ttp.nolst = createstr(tline[0], tline[2], tline[3]);

does not work at all? The error message I recieve is:
tcreate.cpp:55: no matching function for call to `Solver::createstr
(char&, char&)
MainProgram.cpp:44: candidates are: class string
Solver::createstr(char, char, char, char)

All I want to do is have default values for this funtion. I can go
add more 0's in all the function calls, but that seems silly.

I suspect my method of rearranging the contents of strings is not the
ideal solution...but it will do for now.

Thanks,

-Zac



Relevant Pages

  • Re: Is this string input function safe?
    ... return a pointer to mallocated memory holding one input string, ... See my comment after your call to fgets. ... char* malloc_getstr ... before any characters are read, then the ...
    (comp.lang.c)
  • Re: RfD: XCHAR wordset (for UTF-8 and alike)
    ... extended to work with xchars, ... >replacing one char with another. ... before-cursor part, even for fixed-width characters. ... So, should string words ...
    (comp.lang.forth)
  • RE: Fixed Length
    ... match these formats, but rather pull the existing, normal, formats from the ... and run a function to build that information into a string that you ... length and the total lenght of all the fields has to be 100 characters. ... JobId (8 char) ...
    (microsoft.public.access.modulesdaovba)
  • Re: Sorry, newbie question about generating a random string
    ... string grows to a max of 10 characters. ... The real problem is that you are not terminating the string. ... string is an array of characters ending in a null character, ... char myChar; ...
    (comp.lang.c.moderated)
  • Re: Is this code totaly a shit?
    ... | void UppStrg(char *Low, char *Upp, int cnt); ... whitespace-delimited string. ... You're also assuming that the representations of the characters ...
    (comp.lang.c)