Hi again;
Today I've got some silly questions about the translation of an algorithm to c++ :S (hey matrimkar, I found something that should work!:idea: )
well, my questions are in comments in this code:
You can just read the first 2 paragraphs of the code, the 3rd one is quiet the same.

bool b1=false;
            vector<photon>::iterator It1=v1.begin(), It2=v2.begin();
            while(b1==false)
            {
               
               for(int i=It1;i<=v1.end();i++)     //can I affect the value of It1 to i ?
                  {
                  if (v1.at(i)>=*It2)
                     {
                        It1=i;    //I'm doing so because I want the while to know in its (2nd,3rd,...) iteration at which value the for iteration stopped
                        break;
                     }
                  }
               
               if(*It1!=*It2)
                  {
                     for(int i=It2+1;i<=v2.end();i++)   //here it's worse: i=It2+1, I want the i to have the "rank" of the element just after It2
                        {
                           if(v2.at(i)>=*It1)
                              {
                                 It2=i;
                                 if(v2.at(i)==*It2) g++; //dont worry about g, it's an external function
                                 It1++;
                                 break;
                              }
                        }
                  }
                
               else
                  {
                     g++;
                     for(int i=It2+1;i<=v2.end();i++)
                        {
                           if(v2.at(i)>=*(It1+1))
                              {
                              It2=i;
                              if(v2.at(i)==*(It1+1)) g++;
                              It1++;
                              break;
                              }
                        }

               if(It1==v1.end()) b1=true;
                  }  
                   


            }

I'm sorry for double posting, but is there something wrong with my post ? can someone please help ?:(

for(int i=It1;i<=v1.end();i++) //can I affect the value of It1 to i ?

I wouldn't equate It1 with an int. I think you may want something like this:

vector<photon>::iterator It1=v1.begin();
for(int i = 0; It1 != v1.end(); It1++, i++)

or maybe this is easier to understand:

vector<photon>::iterator It1=v1.begin();
int i = 0;
for( ; It1 != v1.end(); It1++)
++i;

either way, i can be used to keep track of the number of times the for loop has run.

Thank you for the proposition.
Finally I adopted this form :

vector<photon>::iterator It1=It1tracker=v1.tab_photon.begin(), It2=It2tracker=v2.tab_photon.begin();
for(It1=It1tracker;It1<=v1.tab_photon.end();It1++)     
                  {
                  if ((*It1)>=(*It2tracker))
                     {
                        It1tracker=It1;
                        break;
                     }
                  }

Now I'm trying to work out an error talking about the >= operator.
Isn't it possible to use this operator in the expression :

if ((*It1)>=(*It2tracker))

???

You need to implement something like
operator >= (const photon & other)
in the photon class, so that the comparison can be made.

thank you mitrmkar!
I corrected that.
I have another error to take care of:

faisceau.cpp: In member function ‘void faisceau::copie_laged(faisceau, double)’:
faisceau.cpp:43: error: a function-definition is not allowed here before ‘{’ token
faisceau.cpp:46: error: ‘fonction1’ was not declared in this scope

referring to this function :

void faisceau::copie_laged(faisceau faisceau_laged,double TAU)
        {   
            double fonction1(photon photon_a_copier,double TAU)
               {
                  return(photon_a_copier.tps_arrive + TAU);
               }
            std::transform( ((*this).tab_photon).begin(), ((*this).tab_photon).end(), faisceau_laged.tab_photon.begin(), fonction1((*this).tab_photon,TAU ));
        }

what I want this function to do is to make a modified copy of the calling faisceau (here it's (*this) ). I want it to add TAU to every tps_arrive of every photon in the new faisceau, faisceau_laged.

to be clear I'll add the classes :

class faisceau
{
    public:
        (.....)
    private:
        std::vector<photon> tab_photon;
        
};
class photon
{
    friend class faisceau;
    public:
        photon(long long ,int );
    private:  
        long long tps_arrive;
        int ponderation;
       
};

I putted the funtion1 on the outside of void faisceau::copie_laged, now it's giving this error :

faisceau.cpp:46: error: conversion from ‘std::vector<photon, std::allocator<photon> >’ to non-scalar type ‘photon’ requested
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.