Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. std::swap won't compile?
QtWS25 Last Chance

std::swap won't compile?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
4 Posts 3 Posters 1.1k 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by davecotter
    #1

    on Windows
    VS 2017 with MSVC2015 libs
    using Creator 4.3.1

    i realize this probably isn't a Qt thing, more of a MS thing. here's my code:

    #include <QCoreApplication>
    #include <algorithm>
    #include <memory>
    #include <utility>
    
    int main(int argc, char *argv[])
    {
    	QCoreApplication	app(argc, argv);
    	
    	int		a=1, b=2;
    	
    	std::swap<int>(a, b);
    	
    	qDebug("a: %d, b: %d\n", a, b);
    	return app.exec();
    }
    

    same code works on mac.
    on windows, i get these errors:

    0_1501259155654_Screen Shot 2017-07-28 at 9.25.45 AM.png

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on last edited by
      #4

      OMG is it that easy? where's the "d'oh!" emoji?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mchinand
        wrote on last edited by
        #2

        Don't include the template type. See this example.

           int a = 5, b = 3;
         
           // before
           std::cout << a << ' ' << b << '\n';
         
           std::swap(a,b);
         
           // after
           std::cout << a << ' ' << b << '\n';
        
        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #3

          And here's the bugreport, it's closed 2013 as By Design :-)

          1 Reply Last reply
          1
          • D Offline
            D Offline
            davecotter
            wrote on last edited by
            #4

            OMG is it that easy? where's the "d'oh!" emoji?

            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