A beginner question about classes

This is a discussion on A beginner question about classes within the C++ Programming forums, part of the General Programming Boards category; Code: #include <string> #include <vector> #include <iostream> using namespace std; class TimeDifference { public: int x,y,z,seconds(string time1, string time2) { ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    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.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    What good would that do, without a main function ?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  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
    3,797
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21