使用界面设计中的功能显示日期

时间:2013-12-13 21:55:26

标签: c++

任何人都可以帮我找出导致这些链接错误的原因:

Error   1   error LNK2019: unresolved external symbol "private: __thiscall Month::Month(int)" (??0Month@@AAE@H@Z) referenced in function "public: static class Month __cdecl Month::Jan(void)" (?Jan@Month@@SA?AV1@XZ)  c:\Users\vigen\documents\visual studio 2012\Projects\Item18TestingInterface\Item18TestingInterface\Source.obj   Item18TestingInterface

Error   2   error LNK1120: 1 unresolved externals   c:\users\vigen\documents\visual studio 2012\Projects\Item18TestingInterface\Debug\Item18TestingInterface.exe    1   1   Item18TestingInterface

当我运行以下代码时

#include <iostream>
using namespace std;

struct Day {
    explicit Day(int d): val(d) {}
    int val;
};

struct Year {
    explicit Year(int y): val(y){};
    int val;
};


class Month {
    public:
        static Month Jan(){return Month(1);}
        static Month Feb(){return Month(2);}
        static Month Mar(){return Month(3);}
        static Month Apr(){return Month(4);}

        static Month May(){return Month(5);}
        static Month Jun(){return Month(6);}
        static Month Jul(){return Month(7);}
        static Month Aug(){return Month(8);}

        static Month Sep(){return Month(9);}
        static Month Oct(){return Month(10);}
        static Month Nov(){return Month(11);}
        static Month Dec(){return Month(12);}

    private:
        explicit Month(int m);
};

class Date {
    public:
        Date(Month& m, const Day& d, const Year& y){};
};

int main () {
    Date date(Month::Jan(), Day(30), Year(1995)); 
}

1 个答案:

答案 0 :(得分:0)

explicit Month(int m);没有定义。将其更改为explicit Month(int m){}应该有效。