| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 694 人关注过本帖
标题:都来找错吧!我也不知道哪里错了,就是显示时间的,也不行。
只看楼主 加入收藏
黄博森
Rank: 2
等 级:论坛游民
帖 子:34
专家分:28
注 册:2014-11-30
结帖率:80%
收藏
已结贴  问题点数:14 回复次数:10 
都来找错吧!我也不知道哪里错了,就是显示时间的,也不行。
//time.h头文件
#ifndef TIME_H
#define TIME_H
class time
{
 private :
    int hour;
    int min;
    int sec;
 public:
     void setH(int h);
     void setM(int m);
     void setS(int s);
     int getH();
     int getM();
     int getS();
     void showtime();
};
#endif;
//实现函数showtime.cpp
#include"time.h"
#include<iostream>
using namespace std;
void time::setH(int h)
{
  hour = h;
}
void time::setM(int m)
{
  min = m;
}
void time::setS(int s)
{
  sec = s;
}
int time::getH()
{
 return hour;
}
int time::getM()
{
 return min;
}
int time::getS()
{
 return sec;
}
void time::showtime()
{
 cout<<"现在时间是:"<<hour<<"时"<<min<<"分"<<sec<<"秒"<<endl;
}
//showtime1.cpp
#include"time.h"
void main()
{
  time t;
  t.setH(12);
  t.setM(23);
  t.setS(56);
  t.showtime();
}
搜索更多相关主题的帖子: private include public 
2014-12-10 15:44
黄博森
Rank: 2
等 级:论坛游民
帖 子:34
专家分:28
注 册:2014-11-30
收藏
得分:0 
--------------------Configuration: showtime1 - Win32 Debug--------------------
Linking...
showtime1.obj : error LNK2001: unresolved external symbol "public: void __thiscall time::showtime(void)" (?showtime@time@@QAEXXZ)
showtime1.obj : error LNK2001: unresolved external symbol "public: void __thiscall time::setS(int)" (?setS@time@@QAEXH@Z)
showtime1.obj : error LNK2001: unresolved external symbol "public: void __thiscall time::setM(int)" (?setM@time@@QAEXH@Z)
showtime1.obj : error LNK2001: unresolved external symbol "public: void __thiscall time::setH(int)" (?setH@time@@QAEXH@Z)
Debug/showtime1.exe : fatal error LNK1120: 4 unresolved externals
执行 link.exe 时出错.

showtime1.exe - 1 error(s), 0 warning(s)
2014-12-10 15:46
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:14 
以下是引用黄博森在2014-12-10 15:44:42的发言:

都来找错吧!我也不知道哪里错了,就是显示时间的,也不行。


这个 也不行  属实是看不懂

DO IT YOURSELF !
2014-12-10 15:46
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
time.h 是系统文件  要不然你换个名字试试

DO IT YOURSELF !
2014-12-10 15:47
黄博森
Rank: 2
等 级:论坛游民
帖 子:34
专家分:28
注 册:2014-11-30
收藏
得分:0 
回复 4楼 wp231957
不行啊,换了也不行
2014-12-10 15:51
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
这样吧

程序代码:
#include <stdio.h>
#include "time.h"
#include "showtime.cpp"

int main(void)
{
    time t;
    t.setH(12);
    t.setM(23);
    t.setS(56);
    t.showtime();
    return 0 ;
}


因为你的showtime.cpp 并没有被编译成库文件  即便你把他弄成库文件了
因为不是系统内定的库文件  所以还需要额外附加到工程中

DO IT YOURSELF !
2014-12-10 15:56
黄博森
Rank: 2
等 级:论坛游民
帖 子:34
专家分:28
注 册:2014-11-30
收藏
得分:0 
回复 6楼 wp231957
Compiling...
showtime1.cpp
e:\huangbosen2\showtime\showtime.cpp(4) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(6) : error C2065: 'hour' : undeclared identifier
e:\huangbosen2\showtime\showtime.cpp(8) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(10) : error C2065: 'min' : undeclared identifier
e:\huangbosen2\showtime\showtime.cpp(12) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(14) : error C2065: 'sec' : undeclared identifier
e:\huangbosen2\showtime\showtime.cpp(16) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(20) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(24) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(28) : error C2653: 'time1' : is not a class or namespace name
执行 cl.exe 时出错.
2014-12-10 16:03
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
以下是引用黄博森在2014-12-10 16:03:47的发言:

Compiling...
showtime1.cpp
e:\huangbosen2\showtime\showtime.cpp(4) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(6) : error C2065: 'hour' : undeclared identifier
e:\huangbosen2\showtime\showtime.cpp(8) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(10) : error C2065: 'min' : undeclared identifier
e:\huangbosen2\showtime\showtime.cpp(12) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(14) : error C2065: 'sec' : undeclared identifier
e:\huangbosen2\showtime\showtime.cpp(16) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(20) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(24) : error C2653: 'time1' : is not a class or namespace name
e:\huangbosen2\showtime\showtime.cpp(28) : error C2653: 'time1' : is not a class or namespace name
执行 cl.exe 时出错.


我的是showtime.cpp 不是showtime1.cpp   要灵活一些 不要照搬

DO IT YOURSELF !
2014-12-10 16:06
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
我的代码都是copy自你的代码  我的都能测试成功 你的为什么会出错呢  自己查一下

DO IT YOURSELF !
2014-12-10 16:06
黄博森
Rank: 2
等 级:论坛游民
帖 子:34
专家分:28
注 册:2014-11-30
收藏
得分:0 
回复 9楼 wp231957
谢谢版主,成功解决,鲜花送上!
2014-12-10 16:18
快速回复:都来找错吧!我也不知道哪里错了,就是显示时间的,也不行。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017808 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved