首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于类的定义和调用有关问题

2012-03-09 
关于类的定义和调用问题程序目的:在Cpp1中定义Time类,在Cpp2中定义Time类的各函数,在Cpp3中调用Time类输出

关于类的定义和调用问题
程序目的:
在Cpp1中定义Time类,在Cpp2中定义Time类的各函数,在Cpp3中调用Time类输出.
程序如下,就是通不过,望高人来指教~~~

Cpp1.cpp

#include   <iostream>
using   namespace   std;

class   Time
{
public:  
void   show(int,   int,   int);
private:
int   hour;
int   minute;
int   second;
}

Cpp2.cpp

#include   <iostream>
#include   "G:\Program\Test\Cpp1.cpp ";
using   namespace   std;
void   Time::show(int   hour,   int   minute,   int   second)
{
cout   < <   hour   < <   ": "   < <   minute   < <   ": "   < <   second;
}

Cpp3.cpp

#include   <iostream>
#include   "Cpp2.cpp "
using   namespace   std;
int   main()
{
Time   t;
t.show(12,35,15);
return   0;
}

[解决办法]
Cpp1.cpp

#include <iostream>
using namespace std;

class Time
{
public:
void show(int, int, int);
private:
int hour;
int minute;
int second;
};//注意要分号

热点排行