funny recursion issue

M

Milan Krejci

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?
 
N

Neelesh Bodas

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
 
O

Obnoxious User

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.
 
M

Milan Krejci

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):
 
N

Neelesh Bodas

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
 
P

Peter

Milan Krejci said:
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?
 

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
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top