Thread: A beginner question about classes

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    1

    Exclamation A beginner question about classes

    Code:
    #include <string>
    #include <vector>
    #include <iostream>
    using namespace std;
    
    
    class TimeDifference
    {
      public:
        int x,y,z,seconds(string time1, string time2)
    
    
    {
            cin >> time1 >> time2;
            x=(time1[0]*10+time1[1])-(time2[0]*10+time2[1]);
             y=(time1[3]*10+time1[4])-(time2[3]*10+time2[4]);
            z=(time1[6]*10+time1[7])-(time2[6]*10+time2[7]);
    return x*3600+y*60+z;
      }
    };
    This is my code. Basically you need to input time in format 11:45:30 and 11:45:45 for example. It should calculate the seconds difference between the two times. I get an error saying "undefined reference to WinMain@16". Please help ASAP. Thanks in advance
    Last edited by Andrej Simeski; 03-18-2012 at 05:30 AM.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Read the following (as you seem to have a broken understanding of these stuff):
    Functions (I) - C++ Documentation
    Functions (II) - C++ Documentation
    Classes (I) - C++ Documentation
    Classes (II) - C++ Documentation
    [7] Classes and objects, C++ FAQ

    Also, it's convenient to use stringstreams to parse the time strings.
    Last edited by manasij7479; 03-18-2012 at 05:35 AM.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    What good would that do, without a main function ?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It will solve the "undefined reference to WinMain@16" error.
    I am assuming there should be a main function somewhere.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    100
    Wait, for one thing, move the "seconds(string time1, string time2)" thing to its own line, like this:

    Code:
    int seconds(string time1, string time2)

  7. #7
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Nicely done Andrej Simeski; that is a wonderful bit of obfuscation.

    [Edit]
    Ah, I didn't notice that this had just been bumped from a couple days back. Sorry.
    [/Edit]

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner C Question Help
    By pmacdonald in forum C Programming
    Replies: 32
    Last Post: 06-22-2011, 09:32 PM
  2. Beginner C Question Help
    By Susan M in forum C Programming
    Replies: 2
    Last Post: 06-22-2011, 07:44 PM
  3. beginner question
    By ShaiAdar in forum C Programming
    Replies: 7
    Last Post: 03-24-2009, 04:55 AM
  4. Beginner question - please help
    By mo34 in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2008, 02:34 PM
  5. Beginner Classes Question
    By kbro3 in forum C++ Programming
    Replies: 9
    Last Post: 08-14-2008, 07:43 AM