私は OOP の初心者です -> 3 つのプライベート変数メンバーを持つクラス Date があり、2 つの方法で日付を出力する必要があります。
- 2010/12/25
- 2010 年 12 月 25 日
エラーが発生する次のコード:
date.obj : エラー LNK2019: 未解決の外部シンボル "public: __thiscall Date::Date(void)" (??0Date@@QAE@XZ) 関数で参照されている "public: void __thiscall Date::printDate(void)" (? printDate@Date@@QAEXXZ) 私が間違っていることは何ですか? 日付.h
#include<iostream>
#include<string>
#ifndef DATE_H
#define DATE_H
class Date
{
private:
    int day;
    int month;
    int year;
public:
    Date();
    Date(int d, int m, int y)
    {
        day=d;
        month=m;
        year=y;
    }
    int getDay() const {return day;}
    int getMonth() const {return month;}
    int getYear() const {return year;}
    void printDate(void);
};
#endif
日付.cpp
#include"date.h"
#include<iostream>
#include<string>
const int NR=12;
void Date::printDate()
{
    Date newDate;
    std::string Months[]={"January","February", "March" , "April", "May", "June", "July", "August", "September", "Octomber", "November", "December"};
    int position;
    std::string month;
    position=newDate.getMonth();
    for(int i=0;i<NR;i++)
    {
        if(i==position)
        {
            month=Months[i];
        }
    }
    std::cout<<month<<" "<<newDate.getDay()<<" "<<newDate.getYear()<<std::endl;
}
main.cpp
#include "date.h"
#include <iostream>
int main()
{
    int d;
    int m;
    int y;
    std::cout<<"Enter day: ";
    std::cin>>d;
    std::cout<<"Enter month: ";
    std::cin>>m;
    std::cout<<"Enter years: ";
    std::cin>>y;
    Date newDate(d,m,y);
    std::cout<<newDate.getMonth()<<"/"<<newDate.getDay()<<"/"<<newDate.getYear()<<std::endl;
    newDate.printDate();
}