Sorting vector<MyClass>

This is a discussion on Sorting vector<MyClass> within the C++ Programming forums, part of the General Programming Boards category; Hi, I am having a problem sorting a vector<MyClass> Code: vector<Faces3D> tmp; // std::sort(tmp.begin(),tmp.end(),ZSort); Faces3D is a simple class that ...

  1. #1
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30

    Unhappy Sorting vector<MyClass>

    Hi,

    I am having a problem sorting a vector<MyClass>

    Code:
    vector<Faces3D> tmp;
    //
    std::sort(tmp.begin(),tmp.end(),ZSort);
    Faces3D is a simple class that only hold 3 indexes to vertices, and the Set/Get methods. my compare function is like that...

    Code:
    bool ZSort(const Faces3D& left, const Faces3D& right)
    {
    //
    if(/**/)return false;
    return true;
    }
    but, altought it look like all the samples i saw in books and in the board, i get this error

    Code:
    d:\Arquivos de programas\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1862): error C2064: el término no se evalúa como una función con 2 argumentos
    d:\Arquivos de programas\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1863): error C2064: el término no se evalúa como una función con 2 argumentos
    d:\Arquivos de programas\Microsoft Visual Studio .NET 2003\Vc7\include\algorithm(1863): fatal error C1903: no se puede recuperar de errores anteriores; se detiene la compilación
    the error c2064 translate to somewhat like "the term is not evaluated as a function with 2 args" in english

    the error is inside <algorithm>, in _Unguarded_partition template

    i am using msvc 2003 .net, spanish version

    thanks for any help,
    jmgk

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    That code looks fine. The error is probably elsewhere, like maybe you didn't declare the ZSort function before you used it with the sort. Could you take the important code and post a small but complete example that we can compile and get that error?

  3. #3
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30
    Daved,

    thanks for the help.

    Your post opened my eyes to search for the bug elsewhere.

    ZSort() was a member function... it was MyClass2::ZSort(), and coz this couldnt be found by the code in <algorithm>, thus the error

    i just made it static, and now all work fine

    thanks again,
    jmgk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting algorithms, worst-case input
    By Leftos in forum C++ Programming
    Replies: 17
    Last Post: 06-15-2009, 02:33 PM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 03:14 AM
  3. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 06:50 PM
  4. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 09:41 PM
  5. selection sorting
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-13-2001, 09:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21