why is returning an int from a pointer crashing my app

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

  1. Milan Krejci

    Milan Krejci Guest

    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?
    }
     
    Milan Krejci, Aug 24, 2007
    #1
    1. Advertising

  2. Milan Krejci

    anon Guest

    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
     
    anon, Aug 24, 2007
    #2
    1. Advertising

  3. Milan Krejci

    Jim Langston Guest

    "Milan Krejci" <> wrote in message
    news:fam5rj$14h7$...
    > 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.
     
    Jim Langston, Aug 24, 2007
    #3
  4. Milan Krejci

    Old Wolf Guest

    On Aug 24, 9:11 pm, "Jim Langston" <> 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.
     
    Old Wolf, Aug 28, 2007
    #4
  5. Milan Krejci

    Jim Langston Guest

    "Old Wolf" <> wrote in message
    news:...
    > On Aug 24, 9:11 pm, "Jim Langston" <> 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.
     
    Jim Langston, Aug 28, 2007
    #5
    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. Schnoffos
    Replies:
    2
    Views:
    1,218
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,645
    Old Wolf
    Jan 20, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,948
    Smokey Grindel
    Dec 2, 2006
  4. aling
    Replies:
    8
    Views:
    956
    Jim Langston
    Oct 20, 2005
  5. Replies:
    9
    Views:
    434
    James Kanze
    Apr 17, 2007
Loading...

Share This Page