This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: simple vector question
- From: Daniel dot Walker at bowneglobal dot com
- To: Benjamin Kosnik <bkoz at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org,libstdc++-owner at gcc dot gnu dot org
- Date: Tue, 11 Dec 2001 17:08:19 -0800
- Subject: Re: simple vector question
vector_type v_c[max];
declares an array of vector_types,
vector_type::reference m = v_c[i]; // 18
deterrences the array and returns the element at index i which is a
vector_type and can't be casted to an int;
I think what you mean to do is initialize the size of the vector to max.
You need to use the constructor for that:
vector_type v_c(max);
Good luck.
Daniel
Benjamin Kosnik
<bkoz@redhat.com> To: libstdc++@gcc.gnu.org
Sent by: cc:
libstdc++-owner@g Subject: simple vector question
cc.gnu.org
12/11/2001 12:44
PM
I must be losing it...
#include <vector.h>
void test01()
{
using namespace std;
typedef int mask;
typedef vector<mask> vector_type;
const int max = 255;
vector_type v_c[max];
vector_type v_de[max];
int i = 0;
mask mask_test = static_cast<mask>(0);
mask mask_is = static_cast<mask>(0);
vector_type::reference m = v_c[i]; // 18
// mask& m = v_c[i];
m = mask_is;
}
int main()
{
return 0;
}
Gives:
vec_tester.cc: In function `void test01 ()':
vec_tester.cc:18: cannot convert `vector<mask, allocator<mask> >' to
`int' in converting
What does this mean? Is this correct? I'd expect
vector_type::reference m = v_c[i]; // 18
to be
vector_type::reference m = vector_type::reference; // 18
which is
int& m = int &; // 18
??
I must be missing something simple.
(And what's up with this error message?)
-benjamin