Help with default arguments in C++
From: Zac Bond (zwb2_at_cwru.edu)
Date: 02/29/04
- Next message: Zac Bond: "Re: Help with default arguments in C++"
- Previous message: Mike Wahler: "Re: help needed with K&R code on p. 87"
- Next in thread: Zac Bond: "Re: Help with default arguments in C++"
- Reply: Zac Bond: "Re: Help with default arguments in C++"
- Reply: Greg Comeau: "Re: Help with default arguments in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Zac Bond: "Re: Help with default arguments in C++"
- Previous message: Mike Wahler: "Re: help needed with K&R code on p. 87"
- Next in thread: Zac Bond: "Re: Help with default arguments in C++"
- Reply: Zac Bond: "Re: Help with default arguments in C++"
- Reply: Greg Comeau: "Re: Help with default arguments in C++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|