已经在Date.obj cpp Class中定义

时间:2015-03-05 20:21:27

标签: c++ class object defined

试图让我的班级工作,但是当我只宣布他们时,它说我已经定义了我的功能。

请参阅https://www.youtube.com/watch?v=b9wialxvcVA了解我要实现的目标。

------------------------------------------------------------------------

//main.cpp    The main file 

#include "std_lib_facilities.h"
#include "Date.cpp"


int main(){

    int mm, hh;

    cout << "Enter the Hours integer" << endl;
    cin >> hh;
    cout << "Enter the Minutes integer" << endl;
    cin >> mm;

    Date firstD(hh, mm);

    cout << "The hours is " << firstD.getHours() << endl << "The minutes are " << firstD.getMinutes() << endl;

    keep_window_open();
    return 0;

}

------------------------------------------------------------------------

//Date.cpp   The definitions of the methods

////Function Definitions
#include "Date.h"

Date::Date(){
    m = 0;
    h = 0;
}

Date::Date(int hh, int mm){
    m = mm;
    h = mm;
}

Date::~Date(){

}

int Date::getMinutes() const{
    return m;
}

int Date::getHours() const{
    return h;
}
------------------------------------------------------------------------

//Date.h       declaring methods and properties

//Header

#ifndef Date_h
#define Date_h

class Date{

public:
    //default constructor
    Date();

    //overload constructor
    Date(int, int);

    //destructor 
    ~Date();

    //accessor methods
    int getMinutes() const;
    int getHours() const;

private:

    //member variables
    int h;
    int m;

};

#endif

注意,“std_lib_facilities.h”是一个头文件,充当有用代码库,以帮助编译等。

提前致谢。

0 个答案:

没有答案