constructors

#include<iostream>
#include<conio.h>
using namespace std ;
class time
{
public:
int hour,min;
time(int);
};
time::time(int a)
{
hour=a/60;
min=a%60;
}

int main()
{
time t1(125);
cout<< t1.hour ;
cout<<"\n";
cout<<t1.min;
getch();
return 0;}

i am gettin the following errors
1)expected ; before t1 in line 18
2)statement is a reference,not call,to function 'time'
3)t1 undeclared in line 19
This code compiles and works. I took out conio.h for aesthetic reasons.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>

using namespace std ;
class time
{
public:
int hour,min;
time(int);
};
time::time(int a)
{
hour=a/60;
min=a%60;
}

int main()
{
time t1(125);
cout<< t1.hour ;
cout<<"\n";
cout<<t1.min;
return 0;}


My guess is that the code you think you're compiling is not actually the code you are compiling.
no it's not compiling.it is still giving me the same errors..i am using dev c++ on windows 7..
any further help is appreciated..
How about this? I suspect you're including the time function, either via iostream, or just because your IDE/compiler/linker does it anyway. http://www.cplusplus.com/reference/clibrary/ctime/time/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
 
using namespace std ;
class timee
{
public:
int hour,min;
timee(int);
};
timee::timee(int a)
{
hour=a/60;
min=a%60;
}
 
int main()
{
timee t1(125);
cout<< t1.hour ;
cout<<"\n";
cout<<t1.min;
return 0;}


Also, stop using Dev-C++

http://www.cplusplus.com/forum/articles/36896/
Last edited on
Topic archived. No new replies allowed.