Newbie with Vector Problem

N

Nichola

Hi Iam trying to learn visual C++ but I have came accross some issues,
I was hoping someone could help.

I have a linked list, in each element there is XYZ float values(point)
and a vector which holds floats.

I want to check the difference between each point in the linked list
and store this into the vector. Sounds ok, BUT I can fill the XYZ
values throughout the linked list and access them later but when it
comes to the vector the values seem to go into the structure but when
I either try to access it later or when Iam debugging the data is
gone?

I have the following code:
in CClass:

#include <vector>
using std::vector;

CClass(float x, float y, float z, vector<float> NameVector);
std::vector<float> CoVector;

In Document Function:

POSITION pos;
for (pos = m_Point.GetHeadPosition(); pos != NULL;)
{
CClass *point = (CClass*)m_Point.GetAt(pos);

// I get the difference value and store it in the diff variable

point->NameVector.push_back(diff);

// the diff variable holds the correct value
}// when it gets to here the value is lost?
point = (CClass *)m_Point.GetNext(pos);

I have tried to access the linked list through another function and
again I can access the XYZ values but nothing is in the vector, Why??

I have also tried to use the Vector.At() function and this still gives
me nothing.

Can anyone help me or post an example of something similar so I can
try to understand what Iam doing wrong. Is it the memory or have I not
initialised the vector?

Thanks in Advance for any help

Nic
 
J

John Harrison

Nichola said:
Hi Iam trying to learn visual C++ but I have came accross some issues,
I was hoping someone could help.

I have a linked list, in each element there is XYZ float values(point)
and a vector which holds floats.

I want to check the difference between each point in the linked list
and store this into the vector. Sounds ok, BUT I can fill the XYZ
values throughout the linked list and access them later but when it
comes to the vector the values seem to go into the structure but when
I either try to access it later or when Iam debugging the data is
gone?

I have the following code:
in CClass:

#include <vector>
using std::vector;

CClass(float x, float y, float z, vector<float> NameVector);
std::vector<float> CoVector;

In Document Function:

POSITION pos;
for (pos = m_Point.GetHeadPosition(); pos != NULL;)
{
CClass *point = (CClass*)m_Point.GetAt(pos);

// I get the difference value and store it in the diff variable

point->NameVector.push_back(diff);

// the diff variable holds the correct value
}// when it gets to here the value is lost?
point = (CClass *)m_Point.GetNext(pos);

I have tried to access the linked list through another function and
again I can access the XYZ values but nothing is in the vector, Why??

I have also tried to use the Vector.At() function and this still gives
me nothing.

Can anyone help me or post an example of something similar so I can
try to understand what Iam doing wrong. Is it the memory or have I not
initialised the vector?

Thanks in Advance for any help

Nic

There is nothing obviously wrong with the code you've posted. Whenever you
have problems with code it always helps the more code you post. It's best of
all if you can post a short complete program that demonstrates the problem.

However you are mixing standard C++ (vector) with non-standard MFC stuff
(CList I think). If your error is in the MFC stuff then you aren't going to
get help here. This group is for standard C++ only. There is also the
problem that if you post MFC code here not everyone is going to understand
it. In general terms I would say that you should switch to list instead of
CList for your linked list, since that is standard (and much better too).
But that doesn't help with your immediate problem.

I would post some more code, don't take short cuts, post the code exactly as
it is in your program, post the declarations of everything (this is
important) and post the code where you are trying to get the values out of
the vector as well as the code where you are putting the values in. Above
all, try and shorten your program, so that you can post more of it here.

John
 

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

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,516
Latest member
ChrisHibbs

Latest Threads

Top