开发者

C ++ class error

i have this code

#include <iostream>
using namespace std;

class time{
            public:

             time();        //constructor

             vo开发者_C百科id 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???


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜