Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [SOLVED][Moved] Where are std::shared_ptr and std::unique_ptr

[SOLVED][Moved] Where are std::shared_ptr and std::unique_ptr

Scheduled Pinned Locked Moved C++ Gurus
9 Posts 3 Posters 16.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    [EDIT: moved to the C++ forum, this is nothing special to Qt, Volker]

    I see the recent release of the SDK has support for plenty of the c++11 features, but when I try to use standard shared and unique smart pointers, Qt Creator says:

    @
    error: 'unique_ptr' is not a member of 'std'@

    Do I need to do something extra to enable smart pointers or they are just not there?

    In VS2010 smart pointers work fine and dandy along with Qt.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Did you ...
      @
      #include <memory>
      @ and did you enable the C++11 language features for MinGW using ... ? @
      QMAKE_CXXFLAGS += -std=gnu++0x
      @
      Notice that it is gnu++0x, not c++0x, which causes some serious compilation errors with MinGW 4.4. C++11 support in 4.4 is mediocre, so expect to run into problems (compiler segfaults and alike). If you want to use C++11 features with MinGW I strongly advise to update ot a recent version.

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        10x, there is "somewhat of a progress"

        Now I get:

        @cc1plus.exe:-1: error: error: unrecognized command line option "-std=gnuc++0x"@

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          It's gnu++0x, not gnuc++0x.

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            Ah, thanks, it is all working fine and dandy now

            BTW I notice unlike plain pointers, Qt Creator does not recognize smart pointer instances as pointers and does not automatically use -> instead of .

            No "intellisense" for the object pointed to methods either, i guess for now c++11 features are "in the blind" for Qt Creator

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              Well, I think that's because smart pointers are first off objects, not pointers (altough they incorporate a pointer). So Qt Creators code completion just works fine here - but it would be indeed a nice feature that some classes can be marked as "pointer classes" which cause Qt Creator to prefer -> over .

              If the problem has been solved for you feel free to prepend the title of your inital post with [Solved] to indicate that there is an solution inside.

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                Yep, the . syntax should get the methods for the actual smart pointer object whereas the -> refers to the object pointed to by the smart pointer. Actually It will be a bad thing if Creator is tuned to automatically convert . to -> for smart pointers, which would make it hard to access the actual pointer member functions, plain C pointers do not have member functions but smart pointers do, the operators for smart pointers have been overloaded to work as plain C pointers but smart pointers are classes.

                But even without automatic . to -> it would be a good thing for Creator to list the members of the object pointed to using ->, since the current version doesn't seem to be able to get to the pointed to object and list members.

                @
                std::unique_ptr<MyClass> uPtr1(new MyClass());
                qDebug() << uPtr1->text();
                qDebug() << (*uPtr1).text();@

                None of the those two methods gets any code completion for MyClass methods

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Saul
                  wrote on last edited by
                  #8

                  Autocomplete works through std::shared_ptr if I add

                  @DEFINES += GXX_EXPERIMENTAL_CXX0X@

                  to my .pro file.

                  I am using the latest build (2.6.0-rc), but this may still work for older builds?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    saedelaere
                    wrote on last edited by
                    #9

                    Autocomplete in 2.6.0 works for me with std::shared_ptr even without the DEFINES Paul postet. But it seems like std::unique_ptr is not supported yet :/

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved