Thread: ctime issue?

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    2

    ctime issue?

    When I run the following code I get two error messages:

    p58Exercise2.cpp(19): error C2533: 't_and_d::__ctor' : constructors not allowed a return type


    p58Exercise2.cpp(19): fatal error C1903: unable to recover from previous error(s); stopping compilation

    I can't figure out why? any help would be apreciated

    I am working with the book "Teach Yourself C++" third edition.
    The excersie I am trying to complete is as follows:
    Create a class called t-and_d that is passed the current system time and date as a parameter to its constructor when it is created. Have the class include a member function that displays this time and date on the screen. (Hint: Use the standard time and date functions found in the standard library to find and display the time and date.)

    I had problems with this one from the start. Finally I worked through it and out of frustraction peeeked at the answer in the back of the book.
    The COde:

    Code:
    // Declare a class called t_and_d, that is passed the current syustem time and date 
    // as a parameter to it constructor when it is created,
    
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    // Declare a class called t_and_d
    class t_and_d { 
      time_t systime;
    
    public:
     t_and_d(time_t t); // constructor
     void show();
    }
    
    
    t_and_d::t_and_d(time_t t)
    {
    	systime = t;
    }
    void t_and_d::show()
    {
    	cout << ctime(&systime);
    }
    
    int main()
    {
    	time_t x;
    
    	x = time(NULL);
    
    	t_and_d ob(x);
    
    	ob.show();
    	return 0;
    }
    thanks,

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    2

    stupid ;

    I left off the ;
    from the class decloration!

    son of a B*!#H!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. type safe issue
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 09:32 PM
  3. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  4. time precision (ctime), tm struct question
    By cjschw in forum C++ Programming
    Replies: 1
    Last Post: 12-26-2003, 01:51 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM