C++ 在其他程序x中包括H文件
对于类,我制作了一个名为time和h的结构,看起来像这样C++ 在其他程序x中包括H文件,c++,include,scope,header-files,include-path,C++,Include,Scope,Header Files,Include Path,对于类,我制作了一个名为time和h的结构,看起来像这样 struct Time{ Time() : hours(0),minutes(0),seconds(0),ticks(0){} int hours, minutes, seconds, ticks; }; Time convert (clock_t t, Time &time); std::string hmst(Time &time); std::string hmst(clock_t t); 后来,
struct Time{
Time() : hours(0),minutes(0),seconds(0),ticks(0){}
int hours, minutes, seconds, ticks;
};
Time convert (clock_t t, Time &time);
std::string hmst(Time &time);
std::string hmst(clock_t t);
后来,我们的老师让我们制作了另一个程序,在这个程序中使用了相同的代码。我没有把它写在上面,而是把它包括在内。第一个问题是这是一个合法的#包含(假设路径是正确的)
第二个问题我需要在我目前正在使用的程序中使用convert函数。我该怎么做呢?我是否会使用范围解析运算符,如下所示
timeobeject=Time::convert(t,time);
还是像这样
timeobject=convert(t,time);
第一个问题是这是一个合法的#包含(假设路径是正确的)
#包括“./p*/r/0*/s/02/time.h”
对。但是请记住,在当前项目中也要编译它的实现文件。或者可以直接链接到对象文件
timeobject=Time::convert(t,Time)
错<代码>转换函数未包含在任何命名空间中。你必须直接这样称呼它-
timeobeject=convert(t,time);
为了更好地适应头文件或源文件的移动,请不要在
#include
语句中放置路径。将路径作为搜索目录提供给编译器(-I)或构建系统/IDE。
timeobeject=convert(t,time);