C++ Using a class from a header within a class

Posted by Kotsuzui on Stack Overflow See other posts from Stack Overflow or by Kotsuzui
Published on 2012-11-08T10:59:06Z Indexed on 2012/11/08 11:00 UTC
Read the original article Hit count: 166

Filed under:
|
|

I'm having a bit of trouble with classes used within classes, from header files.

I have an class time in time.h:

class Time
{
    private:
        int hour, second, minute;

    public:
        . 
        .
        .
        int getHour(int h); 
           etc.
        setHour(); 
           etc.
        void print24hour(); // Prints time in 24 hour format
}

And then, main.cpp:

#include "time.h"

class Class
{
    private:
        string name;
        double grade;

        Time startTime;
        Time endTime;        
    public:
        Class();
        ~Class();

        void setName();
        void setGrade(); 
           etc.           
}

int main()
{
    //Need to print time in 24 hour format, but I don't know how.
    class[i].startTime.print24(getStartTime()); // ??? I'm rather lost
}

I get quite a few "hour, second, minute, etc." are private errors, I'm guessing I'm doing something simple in a rather wrong way. Please help.

© Stack Overflow or respective owner

Related posts about c++

Related posts about class