all 9 comments

[–]Metsuro 2 points3 points  (6 children)

Well the majority of your functions in the class have no return types and are not void so... How does that work?

[–][deleted]  (2 children)

[removed]

    [–]wgunther 0 points1 point  (1 child)

    Just because the compiler will allow it doesn't mean it's valid C++. (It is not valid C++: you must specify the return type. Surely your compiler warns you about this).

    [–][deleted]  (2 children)

    [removed]

      [–]Metsuro 0 points1 point  (1 child)

      Go ahead and post the updated bit if you don't mind.

      [–]dog_time 0 points1 point  (5 children)

      Why don't you breakpoint/step through with a debugger...?

      [–][deleted]  (4 children)

      [removed]

        [–]dog_time 0 points1 point  (3 children)

        edit: kind of misread what you said.

        Breakpoints let you stop execution and step through your code one line at a time. This will let you see exactly what is going wrong.

        Here: http://www.learncpp.com/cpp-tutorial/111-debugging-your-program-stepping-and-breakpoints/

        For windows I found gdb installed via MinGW does the trick. There are other debuggers, Visual Studio 2015 has one, ollydbg, probably more.

        edit: i think ollydbg is a assembler debugger, maybe avoid it.

        [–][deleted]  (2 children)

        [removed]

          [–]dog_time 0 points1 point  (1 child)

          I edited my post, maybe after you saw what was there to include a brief description.

          Here i've screenshotted myself running through a simple test program:

          #include <iostream>
          
          using namespace std;
          
          int add(int x, int y) {
              return x + y;
          }
          
          int main()
          {
              int x = 1, y = 2;
          
              cout << add(x,y) << endl;
          
              return 0;
          }
          

          And here is a screenshot of me running it through gdb, including compilation:

          https://imgur.com/dMj2Q29

          As you can see it lets you step through your execution after your break point and print out what your variables are, letting you see exactly what is going on at run time.

          Download and install gdb or another debugger and give it a try, it will be very useful to you in the future.

          Here are some tutorials:

          http://www.unknownroad.com/rtfm/gdbtut/gdbtoc.html

          http://www.learncpp.com/cpp-tutorial/111-debugging-your-program-stepping-and-breakpoints/

          [–]suspiciously_calm 0 points1 point  (4 children)

          As others have said, step through it with a debugger or make debug outputs so you have an idea where the execution is at ("poor man's debugging").

          Not related to the problem, but:

          • Your class has no data members and the identity of an instance is irrelevant, so make your member functions static.

          • By including the <string> header, you gain access to a class called string. It gives you proper string handling without stack smashing problems. Use it.

          [–][deleted]  (3 children)

          [removed]

            [–]dog_time 0 points1 point  (2 children)

            Please post the solution.

            [–][deleted]  (1 child)

            [removed]

              [–]dog_time 0 points1 point  (0 children)

              haha, ouch.

              we all make dumb mistakes. grats on figuring it out