注册 登录
编程论坛 C++教室

主函数体中函数调用类对象中的错误求助

泡泡 发布于 2008-11-04 22:34, 633 次点击
今天在课本上有一道很简单的例题,我调试了好几遍,但是就是看不出有什么毛病,我在DEV C++编译器里面调试总是出错,实在是受不了,才求助高手指点,谢谢!
源代码如下:
#include<iostream>
using namespace std;
class time
{
   public:
          int hour;
          int minute;
          int second;
};
int main()
{
   void settime(time&);
   void showtime(time&);
   time tt;
   settime(tt);
   showtime(tt);
   system("pause");
   return 0;
}
void settime(time&t)
{
   std::cin>>t.hour;
   std::cin>>t.minute;
   std::cin>>t.second;
   std::cout<<std::endl;
};
void showtime(time&t)
{
     std::cout<<t.hour;
     std::cout<<t.minute;
     std::cout<<t.second;
     std::cout<<std::endl;
};
//请高手纠正
3 回复
#2
youhm2008-11-04 22:47
在VC6.0里没有报错
#3
newyj2008-11-04 23:19
lz定义的类名和c++标准库中的函数 重名了
把类名换了
或者
添加 namespace命名空间
程序代码:
#include<iostream>
using namespace std;

namespace TT
{
  class time
  {
   public:
          int hour;
          int minute;
          int second;
  };
         
}


int main()
{
    using TT::time;
   void settime(time&);
   void showtime(time&);
   time tt;
   settime(tt);
   showtime(tt);
   system("pause");
   return 0;
}

void settime(TT::time& t)
{
   std::cin>>t.hour;
   std::cin>>t.minute;
   std::cin>>t.second;
   std::cout<<std::endl;
}

void showtime(TT::time& t)
{
     std::cout<<t.hour;
     std::cout<<t.minute;
     std::cout<<t.second;
     std::cout<<std::endl;
}
#4
debroa7232008-11-05 01:49
规范命名,会少很多麻烦.
1