473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1572

"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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.