std::reverse not supported?



  • Hi all,
    I'm new to c++ and Qt. I am, and have been a C# VS dev since, well, before it was released and was a Java guy before that. Now that you know who I am, here's my issue I'm having:

    I have a solution that was developed in VS. Within that solution is a vectorUtil.h file. In that file is a method called Reverse which uses void std::reverse( BidirIt first, BidirIt last ). I know that it may be frowned upon to have implementation in a .h file but I didn't write it.

    However, when I integrated the code into a Qt project (Qt Creator 4.3.1 Community), it issues a compile-time error that states, 'reverse' was not declared in this scope. It doesn't appear in intellisense (or whatever it's called in Qt). It's almost as if it's not in the std library. Anybody have any insight?

    I've bold'd the line that the compiler is puking on. Here is the relevant code and includes:

    #pragma once
    
    #ifdef DLL_EXPORT_WIN32
    #ifdef UTILITIES_EXPORTS
    #define UTILITIES_API __declspec(dllexport)
    #else
    #define UTILITIES_API __declspec(dllimport)
    #endif
    #else
    #define UTILITIES_API
    #endif
    #include <vector>
    #include <string>
    using namespace std;
    namespace Utilities
    {
    /// <summary>
        /// Class Property.
        /// Helps with creating abstractions
        /// </summary>
        class UTILITIES_API VectorUtil
        {
        public:
    
    /// <summary>
            /// Reverses the specified data.
            /// </summary>
            /// <param name="data" type="vector<BYTE>&">The data.</param>
            /// <returns>std.vector&lt;_Ty, _Alloc&gt;.</returns>
            template<class Type>
            static vector<Type> Reverse(vector<Type>& data)
            {
                vector<Type> reverseData(data.size());
                Copy(data, 0, reverseData, 0, reverseData.size());
                **reverse(begin(reverseData), end(reverseData));**
    
                return reverseData;
            }
    
        };
    }
    


  • You're missing the #include <algorithm>, see for instance cplusplus.com.



  • Thank you for your response Johan. I had thought that too. I added the #include <algorithm> and then, upon compiling, got the following error:
    [copydata] Error 4

    It's really descriptive and lets me know exactly what is wrong. In searching for it online, I found troves of information on the error... ok, not really. It's not descriptive and there is nothing online about that error that I can find :) However I did notice that I'm on 5.8 and need to be on 5.9.1. I'll update and report back.



  • We can put this one to rest. I upgraded to 5.9.1 and that did the trick. Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.