大家看看这个简单的程序是怎么了呀?(高手莫入)

yuanxulong198010 2002-11-06 08:13:13
下面是我写的一个简单的小程序,但是无法编译通过!
#include <iostream.h>
class mytime
{
public:
int tm_hour;
int tm_min;
int tm_sec;
public:
void get()
{
cout<<tm_hour<<":"<<tm_min<<":"<<tm_sec<<endl;
}
void set(int,int,int);
}
保存为mytime.h文件。
#include "mytime.h"
mytime::set(int h,int m,int s)
{
hour=h;
min=m;
sec=s;
}
保存为mytime.cpp文件。
然后是主文件,如下:
void main() //error:too many type proto>>
{
mytime mtime;
mtime.set(12,35,35);
mtime.get();
} //warning:function should return a value;

为什么不能编译通过呀,是不是我定义的头文件有问题呀,请指教!

...全文
121 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzh_shat 2002-11-06
  • 打赏
  • 举报
回复
//--------mytime.h-------
#include <iostream.h>
class mytime
{
public:
int tm_hour;
int tm_min;
int tm_sec;
public:
void get() {cout<<tm_hour<<":"<<tm_min<<":"<<tm_sec<<endl;}
void set(int h,int m,int s)
{
tm_hour=h;
tm_min=m;
tm_sec=s;
}
};
//-------main.cpp----------
#include"mytime.h"
int main()
{
mytime mtime;
mtime.set(12,35,35);
mtime.get();
return 0;
}


h3wolf 2002-11-06
  • 打赏
  • 举报
回复
//--------mytime.h-------
#include <iostream.h>
class mytime
{
public:
int tm_hour;
int tm_min;
int tm_sec;
public:
void get() {cout<<tm_hour<<":"<<tm_min<<":"<<tm_sec<<endl;}
void set(int,int,int);
}

//--------mytime.cpp-------
#include "mytime.h"
mytime::set(int h,int m,int s)
{
tm_hour=h;
tm_min=m;
tm_sec=s;
}

//-------main.cpp----------
#include "mytime.h"

int main()
{
mytime mtime;
mtime.set(12,35,35);
mtime.get();

return 0;
}
h3wolf 2002-11-06
  • 打赏
  • 举报
回复
把void main()改为int main()
h3wolf 2002-11-06
  • 打赏
  • 举报
回复
hour,min,sec都没定义,主文件应包含"mytime.h",不能通过编译
earphone 2002-11-06
  • 打赏
  • 举报
回复
mytime::set(int h,int m,int s)
{
hour=h;
min=m;
sec=s;
}

你的类中没有定义hour,min,sec三个变量
langzi8818 2002-11-06
  • 打赏
  • 举报
回复
#include <iostream.h>
class mytime
{
public:
int tm_hour;
int tm_min;
int tm_sec;
public:
void get()
{
cout<<tm_hour<<":"<<tm_min<<":"<<tm_sec<<endl;
}
void set(int,int,int);
}//这里缺";"
保存为mytime.h文件。
#include "mytime.h"
mytime::set(int h,int m,int s)//应该加void
{
hour=h;//变量不对
min=m;
sec=s;
}
保存为mytime.cpp文件。
然后是主文件,如下://加#include"mytime.h"
void main() //error:too many type proto>>
{
mytime mtime;
mtime.set(12,35,35);
mtime.get();
} //warning:function should
没有问题了。你好好看看基础的东西吧。
langzi8818 2002-11-06
  • 打赏
  • 举报
回复
#include <iostream.h>
class mytime
{
public:
int tm_hour;
int tm_min;
int tm_sec;
public:
void get()
{
cout<<tm_hour<<":"<<tm_min<<":"<<tm_sec<<endl;
}
void set(int h,int m,int s);
};

void mytime::set(int h,int m,int s)
{
tm_hour=h;
tm_min=m;
tm_sec=s;
}

void main() //error:too many type proto>>
{
mytime mtime;
mtime.set(12,35,35);
mtime.get();
} //warning:function sh
没有问题了
ji_da_sheng 2002-11-06
  • 打赏
  • 举报
回复
//--------mytime.h-------
#include <iostream.h>
class mytime
{
public:
int tm_hour;
int tm_min;
int tm_sec;
public:
void get() {cout<<tm_hour<<":"<<tm_min<<":"<<tm_sec<<endl;}
void set(int,int,int);
}

//--------mytime.cpp-------
#include "mytime.h"
void mytime::set(int h,int m,int s)
{
tm_hour=h;
tm_min=m;
tm_sec=s;
}

//-------main.cpp----------
#include "mytime.h"

void main()
{
mytime mtime;
mtime.set(12,35,35);
mtime.get();
}

dlqcsdn 2002-11-06
  • 打赏
  • 举报
回复
还有一点
就是
在mytime.cpp里面的
mytime::set(int h,int m,int s)
前面还要加一个void
yuanxulong198010 2002-11-06
  • 打赏
  • 举报
回复
其实我在void main()前已经加有头文件#include <mytime.h>,但是不能通过,说变量没有定义,是不是应该这样?
//mytime.cpp
#include <mytime.h>
mytime::set(int h,int m,int s)
{
mytime::hour=h;
mytime::min=m;
mytime::sec=s;
}
是不是这样定义呢,还有呀,是不是只要包含***.h,系统就自动查找它的.cpp文件呀!
内容概要:本文系统研究了Picard迭代法在非线性常微分方程参数估计中的应用,深入阐述了该方法的数学原理及其在参数辨识中的收敛性与稳定性优势。通过构建最小化误差的目标函数,并结合数值积分技术,采用迭代方式逐步逼近系统的真实参数值,有效解决了非线性动态系统中因缺乏解析解而难以进行精确建模的问题。文中提供了完整的Matlab代码实现,涵盖模型定义、迭代求解、参数更新与结果可视化等关键环节,增强了方法的可操作性与工程实用性。研究通过典型非线性系统案例验证了算法的有效性,展示了其在科学计算与工程建模中的良好适应性与推广潜力。; 适合人群:具备常微分方程理论、数值分析基础及Matlab编程能力,从事系统建模、参数辨识、动力学仿真等相关方向的研究生、科研人员和工程技术开发者。; 使用场景及目标:①解决实际工程中非线性微分方程模型的未知参数估计问题;②深入理解Picard迭代法在科学计算中的实现机制与数值特性;③为学术论文复现、科研项目开发或课程设计提供可运行、易调试的技术方案与代码参考。; 阅读建议:建议读者结合文中的数学推导与Matlab代码逐行分析,重点关注迭代流程、目标函数构造与数值积分的耦合实现,通过修改模型结构或噪声条件进行扩展实验,以深化对算法鲁棒性与适用边界的理解。配套资源可通过指定公众号和网盘链接获取,推荐同步学习以加速科研进程。
内容概要:本文详细介绍了一种基于多尺度集成极限学习机(Extreme Learning Machine, ELM)的回归方法,并提供了完整的Matlab代码实现。该方法通过构建多尺度特征表示与集成学习机制,有效提升了ELM在处理非线性、高维复杂数据时的预测精度与模型鲁棒性,特别适用于时间序列回归任务。文档不仅阐述了算法的核心原理与技术流程,还系统展示了其在风电功率预测等工程场景中的应用潜力。同时,文中附带了丰富的科研仿真案例集合,涵盖智能优化算法、深度学习、信号处理、电力系统调度等多个前沿方向,体现了多学科交叉融合的技术优势与实践价值。; 适合人群:具备一定Matlab编程能力,从事科学研究或工程应用的研究生、科研人员及工程技术开发者,尤其适合专注于机器学习、智能算法优化、新能源预测与电力系统建模等相关领域的专业人员。; 使用场景及目标:①用于风电、光伏、负荷等时间序列数据的高精度回归预测任务;②为科研工作者提供可复现的多尺度集成ELM模型代码框架,支持快速算法验证与二次开发;③满足实际工程项目中对高效建模、实时预测与智能决策的技术需求。; 阅读建议:建议读者结合所提供的Matlab代码进行动手实践,深入理解多尺度特征构造与集成策略的设计思想,同时可参考文档中其他相关算法案例进行横向比较与综合应用,以提升整体科研创新能力。

70,039

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧