gcc 4.3.4是否支持unique_ptr? [英] Does gcc 4.3.4 support unique_ptr?

查看:250
本文介绍了gcc 4.3.4是否支持unique_ptr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在我本地的CygWin安装中使用g ++编译器来实现PIMPL,我开始认为这可能是我运行g ++ 4.3.4的事实,因为它的C ++ 11支持并不完美。



使用非常基本的代码(来自MSDN here ):

  my_class.h:
#include <存储器GT&;
class my_class {
public:
my_class();
private:
class impl;的unique_ptr< IMPL> pimpl(新的impl);
};

my_class.cpp:
#includemy_class.h
class my_class :: impl {int my_int; };
my_class :: my_class():pimpl(new impl){};

我尝试使用 g ++ -std = c ++ 0x -o进行编译my_class.o my_class.cpp 结束于:

 在my_class.cpp包含的文件中: 1:
my_class.h:8:错误:ISO C ++禁止声明'unique_ptr'没有类型
my_class.h:8:错误:无效使用'::'
my_class。 h:8:error:expected';'before'<'token
my_class.cpp:在构造函数'my_class :: my_class()'中:
my_class.cpp:5:error:class'my_class '没有任何名为'pimpl'的字段

如果我将 -std = gnu ++ 0x



事实上,当我尝试编译即使是最简单的文件, :

  #include< iostream> 
#include< memory>
int main(){
std :: unique_ptr< int> (new int(30));
}

它抱怨 unique_ptr 不在 std 命名空间中。



gcc c ++ 11 support page 没有 unique_ptr 的条目,但是从查看网络,它已经存在了很长一段时间,至少自<4.4>

所以我的问题是,首先,在什么版本的 gcc 支持 unique_ptr 添加?



另外,am我只是在我的代码中犯了一些骷髅错误,并以错误的方式使用它?在您的第一个示例中,<$ c

解决方案

unique_ptr 缺少$ c> std :: 限定符。第二个示例是正确的C ++ 11



根据 GCC 4.4发行说明 unique_ptr 不在4.4之前的GCC标准C ++库中:
$ b


改进的实验支持对于即将到来的ISO C ++标准C ++ 0x,包括:

$ p

$ ul

  • unique_ptr <算法> 添加,异常传播和对< string> < limits>



  • I've been trying to implement PIMPL using the g++ compiler on my local CygWin install and I'm beginning to think it may be the fact that I'm running g++ 4.3.4, inasmuch as its C++11 support is less than perfect.

    With the very baseline code (from MSDN here):

    my_class.h:
        #include <memory>
        class my_class {
        public:
            my_class();
        private:
            class impl; unique_ptr<impl> pimpl(new impl);
        };
    
    my_class.cpp:
        #include "my_class.h"
        class my_class::impl { int my_int; };
        my_class::my_class(): pimpl( new impl ) {};
    

    I try to compile with g++ -std=c++0x -o my_class.o my_class.cpp and end up with:

    In file included from my_class.cpp:1:
    my_class.h:8: error: ISO C++ forbids declaration of 'unique_ptr' with no type
    my_class.h:8: error: invalid use of '::'
    my_class.h:8: error: expected ';' before '<' token
    my_class.cpp: In constructor 'my_class::my_class()':
    my_class.cpp:5: error: class 'my_class' does not have any field named 'pimpl'
    

    I also get that if I substitute -std=gnu++0x.

    In fact, when I try to compile even the simplest file, lifted from another SO answer:

    #include <iostream>
    #include <memory>
    int main() {
        std::unique_ptr<int> up( new int( 30 ) );
    }
    

    it complains that unique_ptr is not in the std namespace.

    The gcc c++11 support page has no entry for unique_ptr but, from looking at the net, it's been around for quite a while, at least since 4.4.

    So my question is, firstly, at what version of gcc was support for unique_ptr added?

    And, secondly, am I just making some bonehead mistake in my code, using it the wrong way?

    解决方案

    In your first example, the std:: qualifier is missing on unique_ptr. The second example is correct C++11.

    According to the GCC 4.4 release notes, unique_ptr was not in GCC's standard C++ library before 4.4:

    Improved experimental support for the upcoming ISO C++ standard, C++0x, including:

    ...

    • unique_ptr, <algorithm> additions, exception propagation, and support for the new character types in <string> and <limits>.

    这篇关于gcc 4.3.4是否支持unique_ptr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆