Get time <ctime>:

This is a discussion on Get time <ctime>: within the C++ Programming forums, part of the General Programming Boards category; This is a pretty easy program but its failing saying: Code: Undefined symbols for architecture x86_64: Code: "CheapWatch::CheapWatch()", referenced from: ...

  1. #1
    Registered User
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    498

    Get time <ctime>:

    This is a pretty easy program but its failing saying:

    Code:
    Undefined symbols for architecture x86_64:
    Code:
      "CheapWatch::CheapWatch()", referenced from:
          _main in main.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)


    I am not even sure what this even means.


    Code:
    #include <iostream>
    #include <ctime>
    
    using namespace std;
    
    class CheapWatch {
        
    private:
        int hours;
        int minutes;
        int seconds;
        
    public:
        CheapWatch();
        
        void set_values(int);
        int NumSeconds();
        void LocalTime();
        
        
    };
    
    void CheapWatch::set_values ( int Secs ) {
        hours = Secs / 3600;
        minutes = (Secs % 3600) / 60;
        seconds = Secs % 60;
    }
    
    int CheapWatch::NumSeconds()
    {
        return ((hours * 3600) + (minutes * 60) + seconds); //returns number seconds since midnight to confirm
    }
    
    void CheapWatch::LocalTime()
    {
        time_t now = time(0);
        
        char* t = ctime(&now);
        
        cout<<"The current time is: "<<t<<endl;
    }
    
    
    int main()
    {
        CheapWatch watch;
        int sec;
        
        cout<<"How how many seconds after midnight have passed? "<<endl;
        cin>>sec;
        
        watch.set_values(sec);
        cout<<"You have entered "<<sec<<"Which means"<<watch.NumSeconds()<<"Seconds has passed\n";
        
        cout<<"Your local time is: ";
        watch.LocalTime();
        
    
        return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,773
    You forgot to define the CheapWatch default constructor.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    498
    YUP..... That would help.... It works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Date and Time with <ctime>
    By Fekore in forum C++ Programming
    Replies: 2
    Last Post: 11-15-2012, 05:43 PM
  2. time.h ctime and milliseconds
    By Deewhyandy1 in forum C Programming
    Replies: 4
    Last Post: 01-26-2008, 12:42 AM
  3. time precision (ctime), tm struct question
    By cjschw in forum C++ Programming
    Replies: 1
    Last Post: 12-26-2003, 12:51 PM
  4. need help with ctime
    By volk in forum C++ Programming
    Replies: 7
    Last Post: 06-08-2003, 08:02 PM
  5. how to pull system time, date, etc from <ctime>
    By Matt in forum C++ Programming
    Replies: 1
    Last Post: 09-25-2001, 09:08 AM

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