hi
I'm quite new to c++
I just write the following code :
code:
#include<iostream>
using namespace std ;
class time
{
int hour;
int min;
public: time(int a)
{
hour = a/60;
min = a%60 ;
}
};
int main()
{
int a =125;
time t1=a;
cout<< t1.hour ;
cout<<"\n";
cout<<t1.min;
}
I saved it as ti .cpp
I compiled it wit command :
g++ ti.cpp;
it shows following error :
ti.cpp: In function ‘int main()’:
ti.cpp:18: error: expected ‘;’ before ‘t’
ti.cpp:20: error: ‘t’ was not declared in this scope
I dont know what I'm doing wrong ;
how can we invoke constructor like ti=a; ? please explain me this concept
1)main function should have a return type....probably in this case return 0
2)variables hour and min should be in public
3)try changing the class name..ie replace time by some other name...i am advising this because probably your compiler is calling the default time function...