Search code examples
c++includescopeheader-filesinclude-path

Including H files in other programs x


For class I made a struct called time and the h.which looked something like this

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);

Later our teacher had us make another program which used the same code in this program. Rather than writing it over i included. First question is this a legitimate #include (assuming the path is correct)

#include "../p*/*r*/0*/*s/02*/time.h"

Second question I need to use the convert function in the program im currently working on. How would i go about doing this? would i use the scope resolution operator as follows

timeobeject=Time::convert(t,time); 

or like this

timeobject=convert(t,time);

Solution

  • First question is this a legitimate #include (assuming the path is correct)

    #include "../p*/r/0*/s/02/time.h"

    Yes. But remember to compile the implementation file of it as well with the current project. Or you can link directly to the object file.

    timeobeject=Time::convert(t,time);

    Wrong. convert function isn't enclosed in any namespace. You have to directly call it like -

    timeobeject=convert(t,time);