y my vector.front() valur is missing when i call it again?

here is my code
(this part of code is part of my prog)

my question is

why (problem about wrong value outputing)

-----**  22 , 10
-----**  22 , 15
-----**  22 , 15

are not

-----**  15 , 10
-----**  22 , 10
-----**  22 , 15

above is the output of the called  'ptVec"


below is output when i compiled
***************************************
scenario 'c'
********* GL_BEGIN
VirtWidth : 30
VirtHeight : 20
 ADD
 (CAL_W,CAL_H) : 15 , 10
 ADD
 (CAL_W,CAL_H) : 22 , 10
 ADD
 (CAL_W,CAL_H) : 22 , 15
start-end bh : 15,10,22,15
 BH at 15 , 10 , 22 , 15
 POINT (b4 BH) -> 15 , 10
 BH at 15 , 10 , 22 , 10
 POINT (b4 BH) -> 22 , 10
 BH at 22 , 10 , 22 , 15
 POINT (b4 BH) -> 22 , 15
 BH at 22 , 15 , 22 , 15
size of vector : 3
 **************************
-----**  22 , 10
-----**  22 , 15
-----**  22 , 15
 BH at 22 , 10 , 22 , 15
***************************************


            cout << "VirtWidth : " << VirtWidth << "\n";
            cout << "VirtHeight : " << VirtHeight << "\n";
            
            
            float temp1[2];      // start pt. temp
            float temp2[2];
            float temp3[2];
            float temp4[2]; // end point

            int newW;            // calculated point
            int newH;            // calculated point      

            point myObj;
            
            for(int i = 0; i < myvec.size() ; i++)
            {
                  obj& tmp = myvec.at(i);

                  if ( tmp.objtype == obj::COL)
                  {
                        // cout << " is color " << "\n";
                        
                        color[0] = tmp.col[0];
                        color[1] = tmp.col[1];
                        color[2] = tmp.col[2];

                  }
                  else if(tmp.objtype == obj::POINT)
                  {
                                          
                        newW = calW(tmp.pt[0]);
                        newH = calH(tmp.pt[1]);

                        ////////////////////////////////
                        
                        myObj.pt[0] = floor(newW);
                        myObj.pt[1] = floor(newH);
                        
                        ptVec.push_back(myObj);
                        
                        ////////////////////////////////

                        cout << " ADD \n";
                        cout << " (CAL_W,CAL_H) : " << newW << " , " << newH << "\n";
                  
                        SetPixel(newW,newH,color[0],color[1],color[2]);

                  }
                  else if(tmp.objtype == obj::BEGIN)
                  {
                  
                  }
                  else if(tmp.objtype == obj::IDEN)
                  {
                  
                  }
            }

            point& PTtmp = ptVec.front();
            
            temp1[0] = PTtmp.pt[0];            // FIRST POINT
            temp1[1] = PTtmp.pt[1];

            //point& PTtmp3 = ptVec.end();  ????
            point& PTtmp3 = ptVec.at(ptVec.size()-1);

            temp4[0] = PTtmp3.pt[0];
            temp4[1] = PTtmp3.pt[1];
          
            cout << "start-end bh : " << temp1[0] << "," << temp1[1] << "," << temp4[0] << "," << temp4[1] << "\n";
            bh(temp1[0],temp1[1],temp4[0],temp4[1]);

            for(int pt_pos = 0; pt_pos < ptVec.size() ; pt_pos++)
            {
                  point& PTtmp2 = ptVec.at(pt_pos);
                  
                  cout << " POINT (b4 BH) -> " << PTtmp2.pt[0] << " , " << PTtmp2.pt[1] << "\n";

                  temp2[0] = PTtmp2.pt[0];
                  temp2[1] = PTtmp2.pt[1];

                  ////////////////////////////////////////////////
                  // CHECK if the next position is the last one
                  
                  if((pt_pos+1) == ptVec.size())
                  {
                        // already pass the last position
                        // cout << "LAST\n";

                  }
                  else // if the next pos is not the end of vector
                  {
                        PTtmp2 = ptVec.at(pt_pos+1);
                        
                        temp3[0] = PTtmp2.pt[0];
                        temp3[1] = PTtmp2.pt[1];
                  }
                  
                  bh(temp2[0],temp2[1],temp3[0],temp3[1]);
            }

            cout << "size of vector : " << ptVec.size() << "\n";

            // ---------------------------------------------------
            // edge walking
            // ***************************************************

            float t1[2];
            float t2[2];
            float t3[2];
            point& grab = ptVec.front();
            
            t1[0] = grab.pt[0];
            t1[1] = grab.pt[1];
            
            grab = ptVec.at(1);
            
            t2[0] = grab.pt[0];
            t2[1] = grab.pt[1];
            
            grab = ptVec.at(2);
            
            t3[0] = grab.pt[0];
            t3[1] = grab.pt[1];
            /*

            check(temp1[0],temp1[1],grabP1.pt[0],grabP1.pt[1],temp4[0],temp4[1]);
            
            cout << "-----**  " << temp1[0] << " , " << temp1[1] << "\n"; // 15,10
            cout << "-----**  " << grabP1.pt[0] << " , " << grabP1.pt[1] << "\n"; // 22,10
            cout << "-----**  " << temp4[0] << " , " << temp4[1] << "\n"; // 22,15
            
            cout << " ************************** \n";
            cout << "-----**  " << temp1[0] << " , " << temp1[1] << "\n";  // 15,10
            cout << "-----**  " << temp2[0] << " , " << temp2[1] << "\n";  // 22,15
            cout << "-----**  " << temp3[0] << " , " << temp3[1] << "\n";  //   "
            cout << "-----**  " << temp4[0] << " , " << temp4[1] << "\n";  //   "
*/
            cout << " ************************** \n";

            cout << "-----**  " << t1[0] << " , " << t1[1] << "\n";  
            cout << "-----**  " << t2[0] << " , " << t2[1] << "\n";  
            cout << "-----**  " << t3[0] << " , " << t3[1] << "\n";
tom_mkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AxterCommented:
It's hard to give you an answers, since you haven't shown us all your code.

What type is point, and can you post the class declaration for point?

What type is myvec?
0
AxterCommented:

The following section of the code doesn't look right:

point& grab = ptVec.front();

t1[0] = grab.pt[0];
t1[1] = grab.pt[1];

grab = ptVec.at(1);

t2[0] = grab.pt[0];
t2[1] = grab.pt[1];

grab = ptVec.at(2);

t3[0] = grab.pt[0];
t3[1] = grab.pt[1];

First it gets a reference to the first object in ptVec.
Then it changes that object by setting it to the value at  ptVec.at(1)
0
tom_mkAuthor Commented:
all the code is quit long..
and need several file in order to compile..

this might help

struct obj
{

enum type  { POINT, COL, BEGIN, IDEN};

type objtype;

union
{
  float pt[3];
  float col[3];
};  
};

// for GL_LINE_LOOP
struct point
{
      float pt[2];

};

std::vector<obj> myvec;
std::vector<point> ptVec; // to keet the history of pt
0
AxterCommented:
Try changing your code to the following:
t1[0] = ptVec[0].pt[0];
t1[1] = ptVec[0].pt[1];

t2[0] = ptVec[1].pt[0];
t2[1] = ptVec[1].pt[1];

t3[0] = ptVec[2].pt[0];
t3[1] = ptVec[2].pt[1];
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sys_ProgCommented:
Just a note,

when u use vectors, try to use iterators OR the size() function to have a bound check

Have a look at the following code for an example

#include <iostream>
#include <vector>
using namespace std;

int main(int argc, char** argv)
{
   
    vector <int> p ;
   
    p.push_back ( 1 ) ;
    p.push_back ( 2 ) ;
    cout << endl << "Using Indexes" ;
    cout << endl << p [0] ;
    cout << endl << p [1] ;
    cout << endl << p [2] ;
   
    cout << endl << "Using Iterators" ;
    for ( vector<int>::iterator iter = p.begin();iter != p.end() ; iter ++ )
        cout << endl << *iter ;
   
    system ( "PAUSE" ) ;
    return 0;
}

HTH

Amit
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.