0

I am trying to create a class that will run this main program but I'm getting the errors:

Can anyone explain cause/solution to said errors?

Here is my main:

int main()
{
    clockType c1(15, 45, 30), c2(3, 20);  // hour, min, sec
    cout << "c1 is " << c1;   // add whatever to beautify it
    cout << "c2 is " << c2;
    cout << "c1+c2 is " <<  c1+c2;
    c2 = c1+c1;
    cout << "c1+c1 is " << c2;
}

Here is my header file:

#ifndef CLOCKTYPE_H
#define CLOCKTYPE_H
#include <iostream>
#include <ostream>


class clockType
{
friend std::ostream& operator<<(std::ostream& os, const clockType& out);
friend clockType operator+(const clockType& one, const clockType& two);
public:
    clockType();
    clockType(int hours, int minutes, int seconds);
    clockType(int hours, int minutes);
    void setTime(int hours, int minutes, int seconds);
    void getTime(int& hours, int& minutes, int& seconds);
    void printTime();
    void incrementhr();
    void incrementmin();
    void incrementsec();
private:
    int hrs;
    int mins;
    int secs;
};

#endif // CLOCKTYPE_H

Here is my cpp file:

#include "clockType.h"
#include <iostream>
#include <iostream>
using namespace std;

clockType::clockType()
{
    hrs = 0;
    mins = 0;
    secs = 0;
}

clockType::clockType(int hours, int minutes, int seconds)
{
    setTime(hours, minutes, seconds);
}

clockType(int hours, int minutes)
{
    hrs = hours;
    mins = minutes;
    secs = 0;
}

void clockType::setTime(int hours, int minutes, int seconds)
{
    if (0 <= hours && hours < 24)
        hrs = hours;
    else
        hrs = 0;
    if (0 <= minutes && minutes < 60)
        mins = minutes;
    else
        mins = 0;
    if(0 <= seconds && seconds < 60)
        secs = seconds;
    else
        secs = 0;
}

ostream& operator<<(ostream& os, const clockType& out)
{
    os << "Hour is " << out.hrs << "Minute is " << out.mins << "Seconds is " << out.secs;
    return os;
}

clockType operator+(const clockType& one, const clockType& two)
{
    clockType three;
    three.hrs = one.hrs + two.hrs;
    three.mins = one.mins + two.mins;
    three.secs = one.secs + two.secs;
    return three;
}
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83

1 Answers1

1

Your .ccp file contains a number of obvious compile errors. For example this defintion

clockType(int hours, int minutes)

is broken and will not compile. It was apparently supposed to be

clockType::clockType(int hours, int minutes)

The fact that you are not getting/reporting any compile errors for your .cpp file means that you simply forgot to compile your .cpp file as part of the program altogether.

This is why the compiler cannot find the definition. You have to add your .cpp file to your project/makefile/command line (whatever you use). And then you will have to fix the compile errors present in that file.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
  • Hey i'm not sure if i should open a new thread or ask in this one, but i fixed the compile error for that thanks to you and it works but i'm now getting the error: http://i.imgur.com/yv3nOpg.png any advice? – user3264198 Feb 03 '14 at 01:10