C++11 and shared_ptr compile error

Sysprogs forums Forums VisualGDB C++11 and shared_ptr compile error

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #781
    lxh
    Participant

    I’ve added the -std=c++0x flag via the VisualGDB Project Properties dialog in CFGLAGS to utilize the smart pointers such as shared_ptr. That gave me access to the std::shared_ptr all right, and I can define a smart pointer like this:

    class CQueueData
    {
    public:
    CQueueData(void);
    virtual ~CQueueData(void);
    
    virtual std::string getContentType();
    };
    
    typedef std::shared_ptr qd_ptr;

    I can define variables using this qd_ptr, and it compiles. If I want to reference a member of CQueueData through the shared_ptr like this

    void CRaceSvr::ok(int child_socket, qd_ptr dat)
    {
    ... dat.getContentType() ...
    }

    I get the error:

    class std::shared_ptr' has no member named 'getContentType'

    If I reference it as

    dat->getContentType()

    , the error is

    'qd_ptr' has no member named 'getContentType'

    What is wrong?

    note:
    build system: Windows 7 / VS2010 / RaspberryPi
    complete CFLAGS: -ggdb -ffunction-sections -O0 -std=c++0x

    #3044
    support
    Keymaster

    Hi,

    The error with ‘dat.getContentType()’ is by design, as it literally means ‘invoke the getContentType() method of the dat object’ and as the pointer itself does not have a getContentType() method, it produces an error.
    The error with the -> form means that the smart pointer you are using does not define an overloaded “operator->”. Please check the source code of the standard library you are using whether the operator is defined. You can read more about overloading the -> operator here: http://www.tutorialspoint.com/cplusplus/class_member_access_operator_overloading.htm

    #3045
    lxh
    Participant

    using dat->getContentType() is what I expected, but that does not work. In all examples I found using the shared_ptr is that it is a template that should work without defining any overloads.

    Perhaps it is just VisualStudio 2010 that does not implement support for C++11?

    #3046
    support
    Keymaster

    Hi,

    Visual Studio is only involved in IntelliSense; compilation is fully performed by gcc using the standard library that comes with gcc. Please verify that the implementation of shared_ptr that comes with your gcc version has the operator-> defined.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.