Re: [suse-programming-e] STL vector as a function parameter with default value (heres another one for you Jerry...)
I've never used that syntax before, could you explain a little? B-) On Friday 11 February 2005 01:25 pm, Davi de Castro Reis wrote:
I'd like something a little cleaner if possible....
I would go with two func signatures.
func() { vector<uint> a; this->func(a); } func(vector<uint> &foo) {...}
But probably there is an even better way.
[]s Davi de Castro Reis
On Friday 11 February 2005 3:39 pm, Brad Bourn wrote: > I've never used that syntax before, > > could you explain a little? > > B-) > > On Friday 11 February 2005 01:25 pm, Davi de Castro Reis wrote: > > > I'd like something a little cleaner if possible.... > > > > I would go with two func signatures. > > > > func() { vector<uint> a; this->func(a); } > > func(vector<uint> &foo) {...} I think that Davi's solution is relatively portable. In C++, you can have multiple signatures: 1. func() -- Empty parameter list. It simply defines the vector and then calls the other function in the same class. Probably does not need to use this->. 2. func(vector<uint> &foo) -- This is the function that does something with the vector. Because you are calling by reference, I think you must have a vector to reference. Borland may have some non-standard extensions where GCC tends to be a crybaby sometimes. In this case, your code would probably be more portable. You might also want to make func() inline. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Makes sense once you explain it I saw the {...} and thought he was using something to do with C++ capabilities to unlimited (not really) number of paramters. I was thinking too complicatedly. hehehehe duh! simply overloading. sheesh got it! don't know that that is any cleaner than just having a global empty vetor except I suppose someone could actually use it or assign some values or something, where with the overload, it couldn't happen. B-) On Friday 11 February 2005 02:01 pm, Jerry Feldman wrote:
I think that Davi's solution is relatively portable. In C++, you can have multiple signatures: 1. func() -- Empty parameter list. It simply defines the vector and then calls the other function in the same class. Probably does not need to use this->. 2. func(vector<uint> &foo) -- This is the function that does something with the vector. Because you are calling by reference, I think you must have a vector to reference. Borland may have some non-standard extensions where GCC tends to be a crybaby sometimes.
In this case, your code would probably be more portable. You might also want to make func() inline.
-- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
On Friday 11 February 2005 4:16 pm, Brad Bourn wrote:
Makes sense once you explain it
I saw the {...} and thought he was using something to do with C++ capabilities to unlimited (not really) number of paramters.
I was thinking too complicatedly.
hehehehe
duh!
simply overloading. sheesh Think simple. Most programming problems I've faced can be simplified.
-- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
good'ol KISS! hehehe B-) On Friday 11 February 2005 02:33 pm, Jerry Feldman wrote:
On Friday 11 February 2005 4:16 pm, Brad Bourn wrote:
Makes sense once you explain it
I saw the {...} and thought he was using something to do with C++ capabilities to unlimited (not really) number of paramters.
I was thinking too complicatedly.
hehehehe
duh!
simply overloading. sheesh
Think simple. Most programming problems I've faced can be simplified.
-- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
participants (2)
-
Brad Bourn
-
Jerry Feldman