Re: passing vector as argument
- From: Anders Karlsson <anders43@xxxxxxxx>
- Date: Fri, 25 Apr 2008 06:48:21 +0800
On Tue, 22 Apr 2008 22:17:29 -0400, "Igor Tandetnik"
<itandetnik@xxxxxxxx> wrote:
"Daniel" <Mahonri@xxxxxxxxxxxx> wrote in message
news:uAYEWSOpIHA.524@xxxxxxxxxxxxxxxxxxxx
I get an error when I try to define this function:
void print_array(std::vector v);
Like I said, there's no such type as std::vector. You need to provide
the template parameter (it's also better to pass by reference):
void print_array(const std::vector<int>& v);
Alternatively, you could make print_array itself a template:
template <typename T>
void print_array(const std::vector<T>& v);
another common way (and prefered) is to declare a typedef of the
vector, maybe then it's clearer?
typedef std::vector<int> int_vector;
void print_array( int_vector v );
or more effectively (and showing also that the vector is not modified
in the function which the function name already implies):
void print_array( const int_vector &v )
hth/Anders.
--
A: People bitching about top-posting
Q: What's the most annoying thing on USENET?.
- Follow-Ups:
- Re: passing vector as argument
- From: Ron Francis
- Re: passing vector as argument
- References:
- passing vector as argument
- From: Daniel
- Re: passing vector as argument
- From: Igor Tandetnik
- Re: passing vector as argument
- From: Daniel
- Re: passing vector as argument
- From: Igor Tandetnik
- passing vector as argument
- Prev by Date: Re: what is type specifier to print unsigned long long
- Next by Date: Re: passing vector as argument
- Previous by thread: Re: passing vector as argument
- Next by thread: Re: passing vector as argument
- Index(es):
Relevant Pages
|