zoukankan      html  css  js  c++  java
  • c++ g++3.4.5 g++4.8.2 由编译器引起的编译异常

    #include <memory>
    #include <string>
    #include <iostream>
    
    class Student {
    public:
        Student(std::string& name) {
            _name = name;
        }
        ~Student(){
        }
    
        void printName(){
            std::cout << _name << std::endl;
        }
    
    
    private:
        std::string _name;
    };
        
    
    int main() {
        std::string name = "xiaowang";
        std::unique_ptr<Student> p(new Student(name));
        //Student p = Student(name);
        //p.printName();
        p->printName();
    
    
    
        return 0;
    }
    编译:默认g++3.4.5 报如下错误,unique_ptr是c++11的, g++3.4.5似乎也不支持这个。
    
    main.cpp: In function 'int main()':
    main.cpp:41:5: error: 'unique_ptr' is not a member of 'std'
         std::unique_ptr<Student> p(new Student(name));
         ^
    main.cpp:41:28: error: expected primary-expression before '>' token
         std::unique_ptr<Student> p(new Student(name));
                                ^
    main.cpp:41:49: error: 'p' was not declared in this scope
         std::unique_ptr<Student> p(new Student(name));

    后经测试MM提示,改为用
    /opt/compiler/gcc-4.8.2/bin/g++ -std=c++11 main.cpp (原来系统还藏了个高版本的,郁闷,干嘛不直接用高版本的啊)

    编译无误。
    ^
  • 相关阅读:
    bzoj 1503
    bzoj 1193 贪心+bfs
    bzoj 1798 线段树
    Codeforces 804D Expected diameter of a tree
    bzoj 1208
    bzoj 3224
    HDU 5115 区间dp
    hihocoder #1162 矩阵加速dp
    分块入门
    bzoj 1036 树链剖分
  • 原文地址:https://www.cnblogs.com/i80386/p/4793179.html
Copyright © 2011-2022 走看看