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,