0

i have this code

#include <iostream> using namespace std; class time{ public: time(); //constructor void settime(int,int,int); void print(); private: int hour,min,sec; }; //constructor time::time(){ hour=min=sec=0; } int main(){ int num; time t1;//line1 time t2;//line2 cout<<"hello"<<endl; cin>>num; return 0;} 

and the errors in those lines are:

expected `;' before "t1"

[Warning] statement is a reference, not call, to function `time'

for each line

whats the problem???

1 Answer 1

7

There is a std::time function that is imported into the global namespace by your use of using namespace std;. This conflicts with your class named time. This is yet another good reason never to use using namespace std; at namespace scope.

Note, however, that not all standard library implementations respect the rule that names in the standard library that come from the C standard library should not be placed in the global namespace by default.

Another option is to qualify the name time with class, which will allow this to work on any system:

class time t1; class time t2; 

You might also just consider renaming your class.

Sign up to request clarification or add additional context in comments.

1 Comment

... or putting your own time class into a namespace of your own to make it distinct from anything at global scope.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.