不是定义对象之后就自动调用构造函数么,为什么什么结果都没有?(语句没错误)

milito22love 2011-09-27 07:18:58
#include "stdafx.h"
#include <iostream>
using namespace std;

class Time
{
public:
Time(int a,int b,int c)
{

hour=a;
minute=b;
second=c;

}
void shuchuT()
{
cout<<hour<<minute<<second<<"\n";
}

private:
int hour;
int minute;
int second;
};

class Date
{
public:
Date(int d,int e,int f)
{
year=d;
month=e;
day=f;
}
void shuchuD()
{
cout<<year<<month<<day<<"\n";
}
void jiayi(int f)
{
cout<<"第二天是"<<f+1<<"号"<<"\n";
}
private:
int year;
int month;
int day;
};

class DateTime :public Time,public Date
{
public:
DateTime(int d,int e,int f,int a,int b,int c): Date(d,e,f),Time(a,b,c)
{
void shuchuD();
void shuchuT();
void jiayi();
}

};

void main()
{
DateTime yitian(2011,9,27,18,55,59);

}
...全文
57 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
milito22love 2011-09-27
  • 打赏
  • 举报
回复
谢谢 分都给你!!
Jake443403168 2011-09-27
  • 打赏
  • 举报
回复
shuchuD(); //
shuchuT(); //
jiayi(f);
你想有结果当然要调用这几个函数,你那个地方写的是函数声明,不是调用
milito22love 2011-09-27
  • 打赏
  • 举报
回复
求详解 不大明白啊~~
Jake443403168 2011-09-27
  • 打赏
  • 举报
回复

.....
DateTime(int d,int e,int f,int a,int b,int c): Date(d,e,f),Time(a,b,c)
{
shuchuD(); //
shuchuT(); //
jiayi(f); //------------你都没调用
}
.....

64,685

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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