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

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;

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

...全文
100 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文件呀!
内容概要:本文提出一种基于鱼鹰优化算法(OOA)优化的CNN-BiGUR-Attention混合模型,用于提升短期风电功率预测的精度与稳定性,采用Matlab实现代码仿真。该模型融合卷积神经网络(CNN)提取输入数据的局部空间特征,利用双向门控循环单元(BiGUR)捕捉风速、功率等时间序列的前后向动态依赖关系,并引入注意力机制自适应强化关键时间步的特征权重,从而增强模型对非平稳风电数据的表征能力;进一步,采用OOA算法对模型超参数进行全局寻优,有效提升模型收敛速度与泛化性能。研究基于实际风电场历史数据开展实验验证,结果表明,该方法相较传统模型在预测精度、鲁棒性和误差抑制方面表现更优,适用于高比例可再生能源接入背景下的电力系统调度需求。; 适合人群:从事新能源发电预测、电力系统优化调度、智能算法与深度学习融合应用等方向的科研人员及工程技术人员,尤其适合具备Matlab编程能力、熟悉时间序列建模与深度学习框架的研究者。; 使用场景及目标:①实现风电场短期功率高精度预测,支撑电网安全稳定调度与能量管理;②为深度学习模型结构设计与智能优化算法联合调参提供实践范例;③推动人工智能技术在可再生能源预测、智能电网运行等领域的落地应用。; 阅读建议:建议结合提供的Matlab代码深入理解CNN-BiGUR-Attention网络架构搭建、注意力机制实现方式及OOA优化流程,重点关注数据预处理、模型训练与参数调优细节,可通过替换不同风电数据集进行对比实验,进一步掌握模型迁移能力与适应性。

70,037

社区成员

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

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