Vector of structures: non-aggregate error

K

koperenkogel

Dear cpp-ians,

I have a vector of structures:

struct meta_group
{
float id;
float num;
float mean;
float sum;
float sumofsquares;
float std;
struct pixel * head;
struct pixel * tail;
struct pixel * edge_head;
struct pixel * edge_tail;
bool full;
};

vector<meta_group> meta_segment[sizeI[2]];
vector<meta_group>::iterator it_meta_segment;

And now I want to assign values to the elements of this vector by:

for( it_meta_segment = meta_segment.begin(); it_meta_segment!=
meta_segment.end(); it_meta_segment++ ) {
int i = floor((it_meta_segment)/sizeI[0]);
int j = fabs((it_meta_segment)/sizeI[0]);
meta_segment[it_meta_segment].id = it_meta_segment;
meta_segment[it_meta_segment].num = 1;
meta_segment[it_meta_segment].mean = output[j]->value;
....
}

When I compile this I get the following errors:

* request for member `begin' in `meta_segment', which is of
non-aggregate type
* request for member `end' in `meta_segment', which is of
non-aggregate type

What do I do wrong that the begin() and end() do not work. What do I
have to add to solve this problem?

Thanx in advance!

Kind regards,
Stef
 
J

Jeff Schwab

koperenkogel said:
Dear cpp-ians,

I have a vector of structures:

struct meta_group
{
float id;
float num;
float mean;
float sum;
float sumofsquares;
float std;
struct pixel * head;
struct pixel * tail;
struct pixel * edge_head;
struct pixel * edge_tail;
bool full;
};

vector<meta_group> meta_segment[sizeI[2]];

Do you really mean to create an array of vectors? ITYM:

vector<meta_group> meta_segment( sizeI[2] );
 
K

koperenkogel

Indeed, stupid of me.
I was already looking at it for a long time. Too long it seems.

Thank you ,
Stef
 
?

=?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=

koperenkogel wrote:

[...]
When I compile this I get the following errors:

* request for member `begin' in `meta_segment', which is of
non-aggregate type
* request for member `end' in `meta_segment', which is of
non-aggregate type

What do I do wrong that the begin() and end() do not work. What do I
have to add to solve this problem?

Your /meta_segment/ variable is not a std::vector. It is declared as an
array of std::vector and, therefore, cannot have /begin()/ invoked on it.
vector<meta_group> meta_segment[sizeI[2]];

You should have written:

vector<meta_group> meta_segment(sizeI[2]);

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top