| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Milan Krejci" |
| Date: |
24 Aug 2007 03:45:51 AM |
| Object: |
why is returning an int from a pointer crashing my app |
pocet_prac=new int;
*pocet_prac=0;
std::vector <SD >::iterator i;
for (i=vec_prace->begin();i!=vec_prace->end();i++) {
from=(*i).vrat_from(); to=(*i).vrat_to();
doba_prac=this->spojDoby(doba_prac,from,to);
*pocet_prac+=((to+1)-from)/2;
}
int doba::vrat_pocty_hodin_prace() {
return *pocet_prac; //crashes but dont know why?
}
.
|
|
| User: "Jim Langston" |
|
| Title: Re: why is returning an int from a pointer crashing my app |
24 Aug 2007 04:11:08 AM |
|
|
"Milan Krejci" <rdw@no-spam.mail.cz> wrote in message
news:fam5rj$14h7$1@news.vol.cz...
pocet_prac=new int;
*pocet_prac=0;
std::vector <SD >::iterator i;
for (i=vec_prace->begin();i!=vec_prace->end();i++) {
from=(*i).vrat_from(); to=(*i).vrat_to();
doba_prac=this->spojDoby(doba_prac,from,to);
*pocet_prac+=((to+1)-from)/2;
}
int doba::vrat_pocty_hodin_prace() {
return *pocet_prac; //crashes but dont know why?
}
Show us something that acutally compiles. We have no indication where the
code snippet above the function declaration takes place. In mane? In a
constructor? In an initializer? Never?
Since you're getting an error when dereferencing the pointer, I'm guessing
never.
.
|
|
|
| User: "Old Wolf" |
|
| Title: Re: why is returning an int from a pointer crashing my app |
27 Aug 2007 06:33:49 PM |
|
|
On Aug 24, 9:11 pm, "Jim Langston" <tazmas...@rocketmail.com> wrote:
Show us something that acutally compiles. We have no indication where
the code snippet above the function declaration takes place. In mane?
Come on, quit horsing around.
.
|
|
|
| User: "Jim Langston" |
|
| Title: Re: why is returning an int from a pointer crashing my app |
27 Aug 2007 11:13:28 PM |
|
|
"Old Wolf" <oldwolf@inspire.net.nz> wrote in message
news:1188257629.112851.124260@i13g2000prf.googlegroups.com...
On Aug 24, 9:11 pm, "Jim Langston" <tazmas...@rocketmail.com> wrote:
Show us something that acutally compiles. We have no indication where
the code snippet above the function declaration takes place. In mane?
Come on, quit horsing around.
Lol. Yeah, I'm bad at typos.
.
|
|
|
|
|
|
| User: "anon" |
|
| Title: Re: why is returning an int from a pointer crashing my app |
24 Aug 2007 04:07:42 AM |
|
|
Milan Krejci wrote:
pocet_prac=new int;
*pocet_prac=0;
std::vector <SD >::iterator i;
for (i=vec_prace->begin();i!=vec_prace->end();i++) {
from=(*i).vrat_from(); to=(*i).vrat_to();
doba_prac=this->spojDoby(doba_prac,from,to);
*pocet_prac+=((to+1)-from)/2;
}
int doba::vrat_pocty_hodin_prace() {
return *pocet_prac; //crashes but dont know why?
}
I could not even compile it:
sss.cpp:1: error: expected constructor, destructor, or type conversion
before '=' token
sss.cpp:2: error: expected constructor, destructor, or type conversion
before '=' token
sss.cpp:3: error: expected constructor, destructor, or type conversion
before '<' token
sss.cpp:4: error: expected unqualified-id before 'for'
sss.cpp:4: error: expected constructor, destructor, or type conversion
before '!=' token
sss.cpp:4: error: expected constructor, destructor, or type conversion
before '++' token
sss.cpp:10: error: 'doba' has not been declared
sss.cpp: In function 'int vrat_pocty_hodin_prace()':
sss.cpp:11: error: 'pocet_prac' was not declared in this scope
.
|
|
|
|

|
Related Articles |
|
|