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 (原来系统还藏了个高版本的,郁闷,干嘛不直接用高版本的啊)

    编译无误。
    ^
  • 相关阅读:
    json转换字符串
    windows下Xshell远程访问虚拟机
    win7去箭头指令
    n核CPU为什么计算速度达不到单核n倍
    vim字符串的替换
    转发的别人的vim编码和终端编码的设置
    音频操作
    scanf函数
    文字常量区和栈区区别
    Linux 进程
  • 原文地址:https://www.cnblogs.com/i80386/p/4793179.html
Copyright © 2011-2022 走看看