why is returning an int from a pointer crashing my app

M

Milan Krejci

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?
}
 
A

anon

Milan said:
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
 
J

Jim Langston

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

Old Wolf

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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top