funny recursion issue

Discussion in 'C++' started by Milan Krejci, Aug 20, 2007.

  1. Milan Krejci

    Milan Krejci Guest

    hi, this is something i really don't see where the problem might be.

    std::vector <LCDRange *>::iterator it;
    LCDRange *l;
    for (it=vec->begin();it!=vec->end();it++) { //is executed N times
    l=*(it);
    ....
    l->p_doba->vycet_doby(t);
    }

    first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
    "15,31,Nemoc", 3rd time i add "15,31,Svatek".

    vycet_doby function goes like this:
    std::map<SD,std::string>::iterator itd;
    int a,b; SD s;
    vec_prace=new vecSD;
    vec_weekendu=new vecSD;
    vec_svatku=new vecSD;
    vec_nemoci=new vecSD;
    vec_dovolene=new vecSD;
    for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
    { s=itd->first;
    a=s.vrat_from();
    b=s.vrat_to();
    std::cout << a << "-" << b << ":" << itd->second << std::endl;
    ....}
    this, however, outputs:
    15-31:Dovolena
    15-31:Nemoc
    15-31:Svatek
    15-31:Dovolena
    15-31:Nemoc
    15-31:Svatek
    15-31:Dovolena
    15-31:Nemoc
    15-31:Svatek

    N times (3 times in this case). i thought it should output only once for
    each l->p_doba->SDoby. do you get my point?
     
    Milan Krejci, Aug 20, 2007
    #1
    1. Advertising

  2. On Aug 20, 12:31 pm, Milan Krejci <> wrote:
    > hi, this is something i really don't see where the problem might be.
    >
    > std::vector <LCDRange *>::iterator it;
    > LCDRange *l;
    > for (it=vec->begin();it!=vec->end();it++) { //is executed N times
    > l=*(it);
    > ...
    > l->p_doba->vycet_doby(t);
    >
    > }
    >
    > first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
    > "15,31,Nemoc", 3rd time i add "15,31,Svatek".
    >
    > vycet_doby function goes like this:
    > std::map<SD,std::string>::iterator itd;
    > int a,b; SD s;
    > vec_prace=new vecSD;
    > vec_weekendu=new vecSD;
    > vec_svatku=new vecSD;
    > vec_nemoci=new vecSD;
    > vec_dovolene=new vecSD;
    > for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
    > { s=itd->first;
    > a=s.vrat_from();
    > b=s.vrat_to();
    > std::cout << a << "-" << b << ":" << itd->second << std::endl;
    > ...}
    > this, however, outputs:
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    >
    > N times (3 times in this case). i thought it should output only once for
    > each l->p_doba->SDoby. do you get my point?


    Can't get much out of this code, but my guess is that it is because
    you are using a for loop inside vycet_doby function which is itself in
    a for loop.
    -N
     
    Neelesh Bodas, Aug 20, 2007
    #2
    1. Advertising

  3. On Mon, 20 Aug 2007 09:31:29 +0200, Milan Krejci wrote:

    > hi, this is something i really don't see where the problem might be.
    >
    > std::vector <LCDRange *>::iterator it;
    > LCDRange *l;
    > for (it=vec->begin();it!=vec->end();it++) { //is executed N times
    > l=*(it);
    > ...
    > l->p_doba->vycet_doby(t);
    > }
    >
    > first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
    > "15,31,Nemoc", 3rd time i add "15,31,Svatek".
    >
    > vycet_doby function goes like this:
    > std::map<SD,std::string>::iterator itd;
    > int a,b; SD s;
    > vec_prace=new vecSD;
    > vec_weekendu=new vecSD;
    > vec_svatku=new vecSD;
    > vec_nemoci=new vecSD;
    > vec_dovolene=new vecSD;
    > for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
    > { s=itd->first;
    > a=s.vrat_from();
    > b=s.vrat_to();
    > std::cout << a << "-" << b << ":" << itd->second << std::endl;
    > ...}
    > this, however, outputs:
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    >
    > N times (3 times in this case). i thought it should output only once for
    > each l->p_doba->SDoby. do you get my point?


    Post a compilable reduced version of your code demonstrating the problem.

    --
    Obnoxious User
     
    Obnoxious User, Aug 20, 2007
    #3
  4. Milan Krejci

    Milan Krejci Guest

    well, ok, but how do you explain that

    std::vector <SD>::iterator is;
    for (is=vec_svatku->begin();is!=vec_svatku->end();is++) {
    from=(*is).vrat_from(); to=(*is).vrat_to();
    if (from==15 && to==31) doba_svatek=true;
    }
    if (doba_svatek) { ts<<"svatek X\n"; t->append("svatek"); }
    ts=writes into a file
    t=writes a text to a text window.

    in the window i can see "svatek" but in the file there is svatek X three
    or whatever times.

    Neelesh Bodas napsal(a):
    > On Aug 20, 12:31 pm, Milan Krejci <> wrote:
    >> hi, this is something i really don't see where the problem might be.
    >>
    >> std::vector <LCDRange *>::iterator it;
    >> LCDRange *l;
    >> for (it=vec->begin();it!=vec->end();it++) { //is executed N times
    >> l=*(it);
    >> ...
    >> l->p_doba->vycet_doby(t);
    >>
    >> }
    >>
    >> first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
    >> "15,31,Nemoc", 3rd time i add "15,31,Svatek".
    >>
    >> vycet_doby function goes like this:
    >> std::map<SD,std::string>::iterator itd;
    >> int a,b; SD s;
    >> vec_prace=new vecSD;
    >> vec_weekendu=new vecSD;
    >> vec_svatku=new vecSD;
    >> vec_nemoci=new vecSD;
    >> vec_dovolene=new vecSD;
    >> for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
    >> { s=itd->first;
    >> a=s.vrat_from();
    >> b=s.vrat_to();
    >> std::cout << a << "-" << b << ":" << itd->second << std::endl;
    >> ...}
    >> this, however, outputs:
    >> 15-31:Dovolena
    >> 15-31:Nemoc
    >> 15-31:Svatek
    >> 15-31:Dovolena
    >> 15-31:Nemoc
    >> 15-31:Svatek
    >> 15-31:Dovolena
    >> 15-31:Nemoc
    >> 15-31:Svatek
    >>
    >> N times (3 times in this case). i thought it should output only once for
    >> each l->p_doba->SDoby. do you get my point?

    >
    > Can't get much out of this code, but my guess is that it is because
    > you are using a for loop inside vycet_doby function which is itself in
    > a for loop.
    > -N
    >
     
    Milan Krejci, Aug 20, 2007
    #4
  5. On Aug 20, 2:09 pm, Milan Krejci <> wrote:
    > well, ok, but how do you explain that
    >
    > std::vector <SD>::iterator is;
    > for (is=vec_svatku->begin();is!=vec_svatku->end();is++) {
    > from=(*is).vrat_from(); to=(*is).vrat_to();
    > if (from==15 && to==31) doba_svatek=true;
    > }
    > if (doba_svatek) { ts<<"svatek X\n"; t->append("svatek"); }
    > ts=writes into a file
    > t=writes a text to a text window.
    >
    > in the window i can see "svatek" but in the file there is svatek X three
    > or whatever times.
    >
    > Neelesh Bodas napsal(a):


    Please donot top-post.
    Please provide small-sized compilable code that demonstrates the
    problem.

    -N
     
    Neelesh Bodas, Aug 20, 2007
    #5
  6. Milan Krejci

    Peter Guest

    "Milan Krejci" <> wrote in message
    news:fabg0h$2cdb$...
    > hi, this is something i really don't see where the problem might be.
    >
    > std::vector <LCDRange *>::iterator it;
    > LCDRange *l;
    > for (it=vec->begin();it!=vec->end();it++) { //is executed N times
    > l=*(it);
    > ...
    > l->p_doba->vycet_doby(t);
    > }
    >
    > first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
    > "15,31,Nemoc", 3rd time i add "15,31,Svatek".
    >
    > vycet_doby function goes like this:
    > std::map<SD,std::string>::iterator itd;
    > int a,b; SD s;
    > vec_prace=new vecSD;
    > vec_weekendu=new vecSD;
    > vec_svatku=new vecSD;
    > vec_nemoci=new vecSD;
    > vec_dovolene=new vecSD;
    > for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
    > { s=itd->first;
    > a=s.vrat_from();
    > b=s.vrat_to();
    > std::cout << a << "-" << b << ":" << itd->second << std::endl;
    > ...}
    > this, however, outputs:
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    > 15-31:Dovolena
    > 15-31:Nemoc
    > 15-31:Svatek
    >
    > N times (3 times in this case). i thought it should output only once for
    > each l->p_doba->SDoby. do you get my point?
     
    Peter, Aug 21, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Don Tuttle
    Replies:
    2
    Views:
    462
    Don Tuttle
    Oct 13, 2003
  2. Brandon

    Funny Entity Name

    Brandon, Dec 7, 2005, in forum: VHDL
    Replies:
    2
    Views:
    526
    Paul Burke
    Dec 13, 2005
  3. Ron
    Replies:
    2
    Views:
    1,263
    William F. Robertson, Jr.
    Jun 25, 2003
  4. Jullietta
    Replies:
    1
    Views:
    392
    cbDevelopment
    Oct 28, 2004
  5. Replies:
    8
    Views:
    785
    John Reye
    Apr 26, 2012
Loading...

Share This Page