注册 登录
编程论坛 C++教室

类型运算符

FrankloveCyy 发布于 2019-07-24 13:22, 2512 次点击
#include<iostream>
#include<memory>//new include to use unique_ptr
using namespace std;

class Date
{
private:
        int day, month, year;
        string dateInString;
        
public:
     Date(int inMonth,int inDay,int inYear)
        : month(inMonth), day(inDay), year(inYear){};
        
    void DisplayDate()
    {
        cout<< month << " / " << day << " / " << year <<endl;
    }        
};

int main()
{
    unique_ptr<int>smartIntPtr(new int);
    *smartIntPtr = 42;
   
    //Use smart pointer type like an int*
    cout<< "Integer value is: " << *smartIntPtr << endl;
   
    unique_ptr<Date>smartHoliday(new Date(12,25,2016));
    cout<<"The new instance of date contains: ";
   
    //use smartHoliday just as you would a Date*
    smartHoliday->DaisplayDate();
   
    return 0;
}
只有本站会员才能查看附件,请 登录

上面是编译器出的报错,代码明明和书上是一样的,出现报错一头雾水,有大神能给解惑一下吗?
4 回复
#2
rjsp2019-07-24 18:47
你的gcc版本是多少?
另外,编译参数最低要 -std=c++11
#3
FrankloveCyy2019-07-26 11:28
回复 2楼 rjsp
估计应该是下载时候DEV自带编译器的原始版本,没更新过
#4
FrankloveCyy2019-07-26 11:30
回复 2楼 rjsp
好像是4.9.2
#5
rjsp2019-07-26 12:44
gcc 4.9.2 是支持 C++11 的。
你编译时添加上 -std=c++11 试试
1