473,503 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A list of objects with a template member shares address, why ???

Hi

I have a little problem as stated above (haven't found any solution on
the www). I have a list of objects (particles) where I have a member
of a template vector (array1d from TNT). I initialise these members in
the constructor, but when I write different vector values to different
particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem. How
do I initialise the template vector so each particle has it's own
template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?

Thanks for your help

Dennis
Jul 22 '05 #1
14 1579

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution on
the www). I have a list of objects (particles) where I have a member
of a template vector (array1d from TNT). I initialise these members in
the constructor, but when I write different vector values to different
particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem. How
do I initialise the template vector so each particle has it's own
template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?


Here are a list of things that are undefined in the code you posted.

TNT::Array1D<double>
noParticles
emitNoParticles
emit_iterator

I cannot answer this question because these things are undefined, therefore
I cannot understand your code any better than you can.

Please read this, these are some guidelines about how to post code. Follow
these guidelines and you will get your question answered quickly.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

john
Jul 22 '05 #2

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution on
the www). I have a list of objects (particles) where I have a member
of a template vector (array1d from TNT). I initialise these members in
the constructor, but when I write different vector values to different
particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem. How
do I initialise the template vector so each particle has it's own
template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?


Here are a list of things that are undefined in the code you posted.

TNT::Array1D<double>
noParticles
emitNoParticles
emit_iterator

I cannot answer this question because these things are undefined, therefore
I cannot understand your code any better than you can.

Please read this, these are some guidelines about how to post code. Follow
these guidelines and you will get your question answered quickly.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

john
Jul 22 '05 #3

"John Harrison" <jo*************@hotmail.com> wrote in message
news:c4*************@ID-196037.news.uni-berlin.de...

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution on
the www). I have a list of objects (particles) where I have a member
of a template vector (array1d from TNT). I initialise these members in
the constructor, but when I write different vector values to different
particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(


On second thoughts maybe the answer is that TNT::Array1D is rubbish.

Why not use the *standard* vector class std::vector rather than dubious
third party stuff.

typedef std::vector<double> dVector3;

I can promise you that a std::vector does not share memory with another
std::vector. Another advantage of using standard classes is that you can
post code here and everyone will know what you are using.

john
Jul 22 '05 #4

"John Harrison" <jo*************@hotmail.com> wrote in message
news:c4*************@ID-196037.news.uni-berlin.de...

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution on
the www). I have a list of objects (particles) where I have a member
of a template vector (array1d from TNT). I initialise these members in
the constructor, but when I write different vector values to different
particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(


On second thoughts maybe the answer is that TNT::Array1D is rubbish.

Why not use the *standard* vector class std::vector rather than dubious
third party stuff.

typedef std::vector<double> dVector3;

I can promise you that a std::vector does not share memory with another
std::vector. Another advantage of using standard classes is that you can
post code here and everyone will know what you are using.

john
Jul 22 '05 #5
On Sun, 4 Apr 2004 13:38:27 +0100
"John Harrison" <jo*************@hotmail.com> wrote:

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution
on the www). I have a list of objects (particles) where I have a
member of a template vector (array1d from TNT). I initialise these
members in the constructor, but when I write different vector values
to different particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem.
How do I initialise the template vector so each particle has it's
own template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?


Here are a list of things that are undefined in the code you posted.

TNT::Array1D<double>
noParticles
emitNoParticles
emit_iterator

I cannot answer this question because these things are undefined,
therefore I cannot understand your code any better than you can.


Well I thought it would be of no interrest to know the data types for
the above, but the noParticles, emitNoParticle are integers and
emit_iterator is an iterator for the list. But it isn't the iterator
that is a problem as it works when i'm using the array.

Regarding the use of a 3'rd party template is that I don't have to
implement all the functionality needed to make vector and matrix
calculations as that is done in advance.

Dennis
Jul 22 '05 #6
On Sun, 4 Apr 2004 13:38:27 +0100
"John Harrison" <jo*************@hotmail.com> wrote:

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution
on the www). I have a list of objects (particles) where I have a
member of a template vector (array1d from TNT). I initialise these
members in the constructor, but when I write different vector values
to different particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem.
How do I initialise the template vector so each particle has it's
own template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?


Here are a list of things that are undefined in the code you posted.

TNT::Array1D<double>
noParticles
emitNoParticles
emit_iterator

I cannot answer this question because these things are undefined,
therefore I cannot understand your code any better than you can.


Well I thought it would be of no interrest to know the data types for
the above, but the noParticles, emitNoParticle are integers and
emit_iterator is an iterator for the list. But it isn't the iterator
that is a problem as it works when i'm using the array.

Regarding the use of a 3'rd party template is that I don't have to
implement all the functionality needed to make vector and matrix
calculations as that is done in advance.

Dennis
Jul 22 '05 #7

"Dennis" <bu****@cybercity.dk> wrote in message
news:20040404165841.6dde7f69.bu****@cybercity.dk.. .
On Sun, 4 Apr 2004 13:38:27 +0100
"John Harrison" <jo*************@hotmail.com> wrote:

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution
on the www). I have a list of objects (particles) where I have a
member of a template vector (array1d from TNT). I initialise these
members in the constructor, but when I write different vector values
to different particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem.
How do I initialise the template vector so each particle has it's
own template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?


Here are a list of things that are undefined in the code you posted.

TNT::Array1D<double>
noParticles
emitNoParticles
emit_iterator

I cannot answer this question because these things are undefined,
therefore I cannot understand your code any better than you can.


Well I thought it would be of no interrest to know the data types for
the above, but the noParticles, emitNoParticle are integers and
emit_iterator is an iterator for the list. But it isn't the iterator
that is a problem as it works when i'm using the array.

Regarding the use of a 3'rd party template is that I don't have to
implement all the functionality needed to make vector and matrix
calculations as that is done in advance.

Dennis


Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
are just using it incorrectly, perhaps its something completely different.
Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
have to define a suitable copy constructor for sParticle, consult your
documentation.

I don't understand how you expect anyone to be able to solve your problem
with the amount of information given.

john
Jul 22 '05 #8

"Dennis" <bu****@cybercity.dk> wrote in message
news:20040404165841.6dde7f69.bu****@cybercity.dk.. .
On Sun, 4 Apr 2004 13:38:27 +0100
"John Harrison" <jo*************@hotmail.com> wrote:

"Dennis" <dl*******@control.auc.dk> wrote in message
news:ud***********@control.auc.dk...
Hi

I have a little problem as stated above (haven't found any solution
on the www). I have a list of objects (particles) where I have a
member of a template vector (array1d from TNT). I initialise these
members in the constructor, but when I write different vector values
to different particles the values becomes the same.

I have found out that each particles vector are pointing to the same
address :o(
When I used an array instead of a template there where no problem.
How do I initialise the template vector so each particle has it's
own template vector ??

Here are some snippets of code, which might be more understandable
than my rambling:

typedef TNT::Array1D<double> dVector3;
//typedef double dVector3[3];
enum orient {eHoris, eVertic};

//-----------------------------
typedef struct sParticle{
dVector3 position; //position of particle
sParticle():position(3)
{
}
}

list<sParticle> particlePool;
particlePool.resize(noParticles);
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}

this works when i use my array vector, but when using the Array1D
vector the position vector points to the same address for all
particles.

How do I ensure that each particle has its own vector ?


Here are a list of things that are undefined in the code you posted.

TNT::Array1D<double>
noParticles
emitNoParticles
emit_iterator

I cannot answer this question because these things are undefined,
therefore I cannot understand your code any better than you can.


Well I thought it would be of no interrest to know the data types for
the above, but the noParticles, emitNoParticle are integers and
emit_iterator is an iterator for the list. But it isn't the iterator
that is a problem as it works when i'm using the array.

Regarding the use of a 3'rd party template is that I don't have to
implement all the functionality needed to make vector and matrix
calculations as that is done in advance.

Dennis


Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
are just using it incorrectly, perhaps its something completely different.
Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
have to define a suitable copy constructor for sParticle, consult your
documentation.

I don't understand how you expect anyone to be able to solve your problem
with the amount of information given.

john
Jul 22 '05 #9
On 04 Apr 2004 12:26:06 +0200 in comp.lang.c++, Dennis
<dl*******@control.auc.dk> wrote,
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}


I second John's objections, and add that it seems unlikely that you
really want to increment k twice in this loop.

Jul 22 '05 #10
On 04 Apr 2004 12:26:06 +0200 in comp.lang.c++, Dennis
<dl*******@control.auc.dk> wrote,
for(k=0;k<emitNoParticles;k++){
(*emit_iterator).position[0] = k++
}


I second John's objections, and add that it seems unlikely that you
really want to increment k twice in this loop.

Jul 22 '05 #11
"John Harrison" <jo*************@hotmail.com> writes:
Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
are just using it incorrectly, perhaps its something completely different.
Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
have to define a suitable copy constructor for sParticle, consult your
documentation.
Either it is a bug or I have to make a suitable copy constructor,
because it works with the STL::vector
I don't understand how you expect anyone to be able to solve your problem
with the amount of information given.


I'm so sorry, I just hoped that somebody that were using the TNT
package were able to help me. But thanks for your time anyway.

Dennis
Jul 22 '05 #12
"John Harrison" <jo*************@hotmail.com> writes:
Perhaps there is a bug in TNT::Array1D, perhaps there isn't a bug and you
are just using it incorrectly, perhaps its something completely different.
Taking a wild guess perhaps TNT::Array1D uses reference semantics and you
have to define a suitable copy constructor for sParticle, consult your
documentation.
Either it is a bug or I have to make a suitable copy constructor,
because it works with the STL::vector
I don't understand how you expect anyone to be able to solve your problem
with the amount of information given.


I'm so sorry, I just hoped that somebody that were using the TNT
package were able to help me. But thanks for your time anyway.

Dennis
Jul 22 '05 #13
Dennis wrote:

I'm so sorry, I just hoped that somebody that were using the TNT
package were able to help me. But thanks for your time anyway.


I've never even heard of TNT. This is usually not the best place to find
help with particular non-standard libraries. Aside from being off-topic
here, the people qualified to help with them are usually elsewhere. The
library vendor may have a forum or mailing list you can try -- that's
usually the best place to look.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #14
Dennis wrote:

I'm so sorry, I just hoped that somebody that were using the TNT
package were able to help me. But thanks for your time anyway.


I've never even heard of TNT. This is usually not the best place to find
help with particular non-standard libraries. Aside from being off-topic
here, the people qualified to help with them are usually elsewhere. The
library vendor may have a forum or mailing list you can try -- that's
usually the best place to look.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4059
by: Yomanium Yoth Taripoät II | last post by:
HI, 1) what are the differences between list and tuple? 2) how to concatenate tuple and list? no method, no opérator? 3) im looking the fucking manual, and cant add value in my tuple, when it...
7
11453
by: Rolf Hemmerling | last post by:
Hello ! Beginner's question: What ist the easiest way to store and save objects in a file generated by a C++ program, by using the "standard C++ library" and/or "Standard Template Library (...
20
2462
by: Corno | last post by:
Hi all, There's probably a good reason why a const object can call non const functions of the objects where it's member pointers point to. I just don't see it. For me, that makes the the const...
14
403
by: Dennis | last post by:
Hi I have a little problem as stated above (haven't found any solution on the www). I have a list of objects (particles) where I have a member of a template vector (array1d from TNT). I...
4
1243
by: cass | last post by:
Both class A and B inherites from class C. A std::list is used to contain a list of objects of class A or a list of objects of class B, but not both types of classes at the same time. How to...
3
2950
by: Francis Bell | last post by:
Hello, I'm trying to read data from a file and then insert that into a linked list. The way I have it, the program compiles, however, I'm getting a segmentation fault error message when I run...
15
2003
by: Robbie Hatley | last post by:
I was struggling to come up with a way to discern the actual bit patterns of the representations of C++ objects (esp. objects of small built-in types), and I came up with the following mess. But...
4
3004
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:824790 Hi, I have a list of objects (instantiations of class A) in a class B: class B{ //other stuff;...
19
10725
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.