爱吃蔬菜的小人物 2019-03-12 13:09 采纳率: 0%
浏览 1770

为什么 "<<" 会报错, 没有与这些操作数匹配的<<操作符,输出d.day()或者d.year(),也不是输出定义的数据

//头文件just.h

enum class Month
{
jan = 1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
};

class Date
{
public:
Date(int y, Month m, int d);
Month month() { return m; }
int day() { return d; }
int year() { return y; }
private:
int y ;
Month m ;
int d ;
};

Date::Date(int y, Month m, int d)
{

}

//cpp文件
// ones.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include
#include"just.h"
#include"std_lib_facilities.h"
using namespace std;

int main()
{
Date d{ 2000, Month::jun, 12 };
cout << d.month() << '\n';
}

  • 写回答

4条回答 默认 最新

  • J4cks0n 2019-03-12 16:16
    关注

    你都用了enum class 了你觉得的

    给你个代码片 ,直接把上面的东西放在单文件里了 你看下

    #include <iostream>
    
    using namespace std;
    
    enum class Month : int 
    {
        jan = 1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
    };
    
    class Date
    {
        public:
            Date(int v_year, Month v_month, int v_day) :
            m_year(v_year),m_month(v_month),m_day(v_day){};
    
            Month get_month() { return m_month; }
            int get_day() { return m_day; }
            int get_year() { return m_year; }
        private:
            int m_year ;
            Month m_month ;
            int m_day ;
    };
    
    int main()
    {
        Date m_date{ 2000, Month::jun, 12 };
        cout << static_cast<int>(m_date.get_month()) << endl;
        cout << m_date.get_day() << endl;
        cout << m_date.get_year() << endl;
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!