I did as this answer says but it gives an error. There are three files in my program. The main
function, a .h
file and a .cpp
file. When I included the .h
file in main
it didn't work but when I included the .cpp
file, declared in .h
file, it worked fine.
main.cpp
//#include 'mathematica.h' didnt work but 'mathematica.cpp'
mathematica.h
//declarations
mathematica.cpp
//included 'mathematica.h', //Definitions
What am I missing?
//main.cpp
#include <iostream>
#include "mathematica.h"
using namespace std;
int main()
{
}
//mathematica.h
#ifndef MATHEMATICA_H_INCLUDED
#define MATHEMATICA_H_INCLUDED
class time //time class start
{
private:
//Member variables
int second, minute, hour;
public:
//Constructors
time();
time(int,int,int);
//Member Functions
void display() const;
void add_times(const time&,const time&);
}; //time class end
#endif // MATHEMATICA_H_INCLUDED
//mathematica.cpp
#include <iostream>
#include "mathematica.h"
using namespace std;
//Definition of the class 'time'
//start
//Constructor
time :: time(): hour(0), minute(0), second(0) {}
//Overloaded Constructor
time :: time(int h,int m,int s): hour(h), minute(m), second(s) {}
//display() Member Function
void time :: display() const
{
cout<<hour<<"H:"<<minute<<"M:"<<second<<"S"<<endl;
}
//add_times() Member Function
void time :: add_times(const time& obj1,const time& obj2)
{
hour = obj1.hour + obj2.hour;
minute = obj1.minute + obj2.minute;
second = obj1.second + obj2.second;
}