小编use*_*317的帖子

C++在构造函数中定义const

我在第30行遇到错误(const Date date2 = new Date(2012年12月31日);)

错误消息是:从'Date*'转换为请求的非标量类型'const Date'

以下是我的源代码:

class Date
{
private :
    int day ;
    int month ;
    int year ;
public :
    Date(){
        day = 1;
        month = 1;
        year = 2000;
    }
    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 ;}
};

int main ()
{
    const Date date ; …
Run Code Online (Sandbox Code Playgroud)

c++ constructor const

0
推荐指数
1
解决办法
158
查看次数

标签 统计

c++ ×1

const ×1

constructor ×1