Discussion:
vector of struct
(too old to reply)
Steve
2008-07-27 14:13:58 UTC
Permalink
Hi all,

Having a few problems in BCB5 with the following. Any advice will be
greatly received.

I have a struct as so:

typedef struct
{
double min;
double qt1;
double med;
double qt3;
double max;
} sTestStats;

I then declare a vector of structs like:

vector<sTestStats> wfrStats;

I then try to fill it with:

tmpData.min = min(data);
tmpData.qt1 = percentile(data, 0.25);
tmpData.med = median(data);
tmpData.qt3 = percentile(data, 0.75);
tmpData.max = max(data);
wfrStats.push_back(tmpData);

where tmpData is a local variable of the above struct type.

However, when my program runs, the data doesn't appear to be going into
the vector. When I debug what's going on and try looking at wfrStats[0],
the debugger shows the message:

wfrStats[0]: E2094 'operator+' not implemented in type
'std::vector<sTestStats, std::allocator<sTestStats> >' for arguments of
type 'int'


What does this mean? What have I done wrong, or what have I not done?

Thanks for reading.
S
Ed Mulroy [TeamB]
2008-07-27 14:37:16 UTC
Permalink
sTestStats has no members named median or percentile. While you describe
it, tmpData could be a source of the problem and the actual declaration for
it is not shown.

Please use cut and paste from the actual code to put information into a
message so that we've a fighting chance of figuring out what might be going
wrong.

. Ed
Post by Steve
Having a few problems in BCB5 with the following. Any advice will be
greatly received.
typedef struct
{
double min;
double qt1;
double med;
double qt3;
double max;
} sTestStats;
vector<sTestStats> wfrStats;
tmpData.min = min(data);
tmpData.qt1 = percentile(data, 0.25);
tmpData.med = median(data);
tmpData.qt3 = percentile(data, 0.75);
tmpData.max = max(data);
wfrStats.push_back(tmpData);
where tmpData is a local variable of the above struct type.
However, when my program runs, the data doesn't appear to be going into
the vector. When I debug what's going on and try looking at wfrStats[0],
wfrStats[0]: E2094 'operator+' not implemented in type
'std::vector<sTestStats, std::allocator<sTestStats> >' for arguments of
type 'int'
What does this mean? What have I done wrong, or what have I not done?
Darko MIletic
2008-07-27 14:49:52 UTC
Permalink
Post by Steve
Hi all,
Having a few problems in BCB5 with the following. Any advice will be
greatly received.
The code is correct and should work just fine. That error is strange.
I think you are not showing us complete code as something is missing
here. Probably you are trying to add numeric value to the vector itself
and that of course will not work.

int p = wfrStats[0] + 1; //this will produce the error you mention
double d = wfrStats[0].min + 1.0; //this however is fine
Steve
2008-07-27 15:58:33 UTC
Permalink
Hi guys,

Thanks for your replies. I realize I left a few bits of info out, but
the code I entered was cut and pasted from BCB. Anyway,

tmpData is declared as so:

sTestStats tmpData;

'data' is a vector of doubles.

min, median, percentile & max are all external functions that return a
double after passing a vector of some type. There is no problem (that I
can see) with the filling for the tmpData structure.

What I actually have is a vector of vectors of the above struct,
declared as so:

typedef vector<sTestStats> waferStatsType;
typedef vector<waferStatsType> batchStatsType;
batchStatsType stats;

Then I use tmpData to add the information to vector, wfrStats. Then,
when I've add all the info I need to wfrStats, I do:

stats.push_back(wfrStats);

wfrStats is actually declared like:

waferStatsType wfrStats;

I don't know what else to add. I didn't think I was using ints anywhere,
or the + operator.

Thanks again for your input.

S
Post by Steve
Hi all,
Having a few problems in BCB5 with the following. Any advice will be
greatly received.
typedef struct
{
double min;
double qt1;
double med;
double qt3;
double max;
} sTestStats;
vector<sTestStats> wfrStats;
tmpData.min = min(data);
tmpData.qt1 = percentile(data, 0.25);
tmpData.med = median(data);
tmpData.qt3 = percentile(data, 0.75);
tmpData.max = max(data);
wfrStats.push_back(tmpData);
where tmpData is a local variable of the above struct type.
However, when my program runs, the data doesn't appear to be going into
the vector. When I debug what's going on and try looking at wfrStats[0],
wfrStats[0]: E2094 'operator+' not implemented in type
'std::vector<sTestStats, std::allocator<sTestStats> >' for arguments of
type 'int'
What does this mean? What have I done wrong, or what have I not done?
Thanks for reading.
S
Steve
2008-07-27 16:49:23 UTC
Permalink
More info,

In my method that fills the vector, if I declare a test variable at the
start of the method like this:

vector<sTestStats> test;

Then break execution at the next line and hover over 'test' The popup
only shows { } which I assume indicates that the vector didn't create
properly?

I have tried exactly the same code in a new test app, and it works, the
vector gets created, and the popup shows a start and end address as
expected.

Does this give any further pointers?

Many thanks,
S
Post by Steve
Hi guys,
Thanks for your replies. I realize I left a few bits of info out, but
the code I entered was cut and pasted from BCB. Anyway,
sTestStats tmpData;
'data' is a vector of doubles.
min, median, percentile & max are all external functions that return a
double after passing a vector of some type. There is no problem (that I
can see) with the filling for the tmpData structure.
What I actually have is a vector of vectors of the above struct,
typedef vector<sTestStats> waferStatsType;
typedef vector<waferStatsType> batchStatsType;
batchStatsType stats;
Then I use tmpData to add the information to vector, wfrStats. Then,
stats.push_back(wfrStats);
waferStatsType wfrStats;
I don't know what else to add. I didn't think I was using ints anywhere,
or the + operator.
Thanks again for your input.
S
Post by Steve
Hi all,
Having a few problems in BCB5 with the following. Any advice will be
greatly received.
typedef struct
{
double min;
double qt1;
double med;
double qt3;
double max;
} sTestStats;
vector<sTestStats> wfrStats;
tmpData.min = min(data);
tmpData.qt1 = percentile(data, 0.25);
tmpData.med = median(data);
tmpData.qt3 = percentile(data, 0.75);
tmpData.max = max(data);
wfrStats.push_back(tmpData);
where tmpData is a local variable of the above struct type.
However, when my program runs, the data doesn't appear to be going
into the vector. When I debug what's going on and try looking at
wfrStats[0]: E2094 'operator+' not implemented in type
'std::vector<sTestStats, std::allocator<sTestStats> >' for arguments
of type 'int'
What does this mean? What have I done wrong, or what have I not done?
Thanks for reading.
S
Leo Siefert
2008-07-28 11:33:27 UTC
Permalink
Post by Steve
Does this give any further pointers?
Yes. It tells us that you have not provided the code that is causing
the problem. You give a lot more description than you do code, but the
description tells only what you intend the missing code to do, and the
code you provide is code that you say works in a test app. That makes
it clear that it is other code that is causing your problems.

If you want help you really need to provide code that is complete and
compilable and that shows the problem as well. Chances are that in
creating a simple demo of the problem you will actually find it on
your own.

- Leo
Steve
2008-07-28 12:01:56 UTC
Permalink
Hi Leo,

Thanks for the reply. I'm really struggling to reproduce the problem. It
only appears to give me problems in the method where I declare the vector.

In fact, I put a test declaration in that form's c'tor and it created
correctly. I then moved the test declaration to my method and it worked
there too. Things now seem to be working but I don't know why.

I did notice the laptop I was working on was *extremely* hot, but I
don't understand why this would cause such a specific problem.

Anyway, until I find a way to reproduce the problem in a small piece of
post-able code, I guess I'll carry on scratching my head.

Thanks all for your input though,

S
Post by Leo Siefert
Post by Steve
Does this give any further pointers?
Yes. It tells us that you have not provided the code that is causing
the problem. You give a lot more description than you do code, but the
description tells only what you intend the missing code to do, and the
code you provide is code that you say works in a test app. That makes
it clear that it is other code that is causing your problems.
If you want help you really need to provide code that is complete and
compilable and that shows the problem as well. Chances are that in
creating a simple demo of the problem you will actually find it on
your own.
- Leo
Chris Uzdavinis (TeamB)
2008-07-28 13:04:37 UTC
Permalink
Post by Steve
Hi all,
Having a few problems in BCB5 with the following. Any advice will be
greatly received.
typedef struct
{
double min;
double qt1;
double med;
double qt3;
double max;
} sTestStats;
Instead of aliasing an anonymous struct with a typedef (the C way),
you'd be better off with a named struct directly.

struct sTestStats { ... };
Post by Steve
vector<sTestStats> wfrStats;
You don't show how you include vector, and you don't have the
namespace std:: qualification, and you're not using std::vector, and
your not using namespace std. So this shouldn't compile, or your code
is incomplete, and we're not able to really help diagnose problems.

...
Post by Steve
wfrStats[0]: E2094 'operator+' not implemented in type
std::vector<sTestStats, std::allocator<sTestStats> >' for arguments of
type 'int'
This is a strange error that Borland compilers have given for years
which is nearly meaningless in what it says, but it means you're
trying to use the operator[] on a const object, and there is not const
member function overloading operator [].

You are clearly doing a lot more in your program that your post
suggests.... I wouldn't be surprised if you're modifying a copy of
your vector, or passing it around to a function as a reference to
const and trying to change that, or something else strange.
--
Chris (TeamB);
Hendrik Schober
2008-07-28 22:11:10 UTC
Permalink
Post by Steve
[...]
However, when my program runs, the data doesn't appear to be going into
the vector. When I debug what's going on and try looking at wfrStats[0],
wfrStats[0]: E2094 'operator+' not implemented in type
'std::vector<sTestStats, std::allocator<sTestStats> >' for arguments of
type 'int'
What does this mean? What have I done wrong, or what have I not done?
As Chris says it's just the way BCC reports a missing []
operator. (With pointers, 'a[b]' is the same as '*(a+b)'*),
so that's probably why it reports + when it misses [].)
OTOH, if that's the debugger reporting, it might just not
be able to call that operator using its infix syntax. Have
you tried 'wfrStats.operator[](0)' (or 'wfrStats.at(0)')?
Post by Steve
Thanks for reading.
S
HTH,

Schobi

*) Interestingly, since '*(a+b)' is the same as '*(b+a)',
in POD land 'a[b]' is the same as 'b[a]'.
--
***@gmx.de is never read
I'm HSchober at gmx dot de
"I guess at some point idealism meets human nature and
explodes." Daniel Orner
Vaclav Cechura
2008-07-30 14:05:49 UTC
Permalink
Post by Hendrik Schober
*) Interestingly, since '*(a+b)' is the same as '*(b+a)',
in POD land 'a[b]' is the same as 'b[a]'.
Which I call one of the weirdest things retained in C++, that
allows such lines to compile:

0[s] = 1[s];

Does not make much sense to me in C++. Ok, it's said to be
easier for the compiler, but is it enough for it to be allowed?
And according to the Standard the compiler should check if one
of the operands in the expression "E1[E2]" is a pointer and the
other an integral/enumeration type, and if you imagine that
test,you'll see that it could reject the form "0[s]" very easily
with almost no overhead.

Vaclav
Chris Uzdavinis (TeamB)
2008-07-30 15:14:10 UTC
Permalink
Post by Vaclav Cechura
Does not make much sense to me in C++. Ok, it's said to be
easier for the compiler, but is it enough for it to be allowed?
And according to the Standard the compiler should check if one
of the operands in the expression "E1[E2]" is a pointer and the
other an integral/enumeration type, and if you imagine that
test,you'll see that it could reject the form "0[s]" very easily
with almost no overhead.
But then you couldn't write code like 3["abcdef"].
--
Chris (TeamB);
JohnC
2008-07-30 15:56:30 UTC
Permalink
This would be a loss ?
Post by Chris Uzdavinis (TeamB)
But then you couldn't write code like 3["abcdef"].
Loading...