Mailinglist Archive: opensuse-programming (62 mails)

< Previous Next >
Re: [suse-programming-e] STL vector as a function parameter with default value (heres another one for you Jerry...)
  • From: Jerry Feldman <gaf@xxxxxxx>
  • Date: Fri, 11 Feb 2005 16:01:21 -0500
  • Message-id: <200502111601.21350.gaf@xxxxxxx>
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@xxxxxxx>
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

< Previous Next >
Follow Ups
References