On 12/17/2012 4:34 PM, Elzbieta Burnett wrote:
> On Dec 17, 3:33 pm, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
>> Elzbieta Burnett <elzbieta.burn...@gmail.com> wrote in news:735599ee-
>> c452-4879-a11b-498299530...@f4g2000yqh.googlegroups.com:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> I have:
>>
>>> struct point
>>> {
>>> double alpha, beta;
>>> double Force;
>>
>>> point( double a, double b, double f ) : alpha(a), beta(b), Force(f)
>>> {}
>>> };
>>
>>> struct data
>>> {
>>> int dof;
>>> int XYZ;
>>> double X, Y, Z;
>>> int node;
>>> vector<point> pt;
>>> };
>>
>>> map<int, data> AeroDOF;
>>
>>> I my initialization code I had:
>>
>>> AeroDOF[ dof[j] ].pt.push_back( point( alpha[i], beta[i],
>>> Force[i][j] ) );
>>
>> Your conclusion is right, but it does not follow from the above line. In
>> this line [] is used a lot, but the only case where the container type is
>> known it is a map (AeroDOF). All other variables where [] is applied to
>> are undefined/undeclared (dof, alpha, beta, Force) in your example and so
>> it is not clear if they are vectors, not to speak about how large they
>> are and if they are accessed out of bounds.
>>
>>
>>
>>> I thought that vector '[]' would create an instance of 'point' (like
>>> map '[]'), call copy constructor and assign newly created entry to
>>> point( alpha[i], beta[i], Force[i][j] ) in AeroDOF.pt.
>>
>> On pt you are using push_back() which works more or less exactly as you
>> describe. Your problem is probably elsewhere.
>>
>> Cheers
>> Paavo
>
> If I use solution proposed by John:
>
> vector<point *> pt)
> AeroDOF[ dof[j] ].pt.push_back( new point( alpha[i], beta[i], Force[i]
> [j] ) );
>
> this seems to work. Is there problem with this solution?
Only if you consider unnecessary use of pointers a problem. Try
vector<point> pt; // same as you had before
...
... pt.push_back(point(alpha[i]...
I.e. without the pointers and without the 'new'.
V
--
I do not respond to top-posted replies, please don't ask
|