compile time error

I have a function called compr

1
2
3
4
bool class1::compr(const structT1& t1, const structT1& t2)
{          
    return t1.dateTime > t2.dateTime;
}


and I am using it for sorting a vector on the basis of time

std::sort(vecT1->begin(), vecT1->end(), compr);

it is giving me an error which is as follows

error: argument of type ‘bool (class1::)(const class1::structT1&, const class1::structT1&)’ does not match ‘bool (class1::*)(const class1::structT1&, const class1::structT1&)’

I am compiling this program on Linux

Could anyone please help
you cannot provide a member function this way and you don't need to. just remove 'class1::' before compr and you're done
Thanks coder777 but it is still giving some error

the snippet of code I am working on is

[code removed]


Last edited on by admin
I have removed the class1 where you suggested but now it is giving me another error

1
2
3
4
5
6
7
class1.cpp:63: error: ISO C++ forbids declaration of ‘structT1’ with no type
class1.cpp:63: error: expected ‘,’ or ‘...’ before ‘&’ token
class1.cpp: In function ‘bool compr(int)’:
class1.cpp:65: error: ‘t1’ was not declared in this scope
class1.cpp:65: error: ‘t2’ was not declared in this scope
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/algorithm:62,
                 from class1.cpp:6:
Thanks coder it is working now :) but will get back if it stops working again :D
ok the function is static. That changes the situation so then don't remove remove 'class1::' before compr instead write std::sort(vecT1->begin(), vecT1->end(), &compr); // note that '&'

hope that helps
OK THANKS A LOTTT [:-)]
Hello again Coder777. Could you please have a look at the error below.

[code removed]

and this is the error

[code removed]
Last edited on by admin
replacing this line

bool operator<( const block& iBlockLhs)

with this one

 
bool operator<( const block& iBlockLhs) const


has solved the problem. Am I right?
That bool operator<( const block& iBlockLhs) must be bool operator<( const block& iBlockLhs) const // note that const
Thanks :-)
Hello Coder777. Please have a look at my problem

I want to find out all the matches (could be more than two) between itFirst and itCurrent i-e all matches in the vector my_file_as_blocks. Could you please tell me how/where do I increment/change_value_of the itFirst? OR how/where do I match each value of itCurrent with itFirst?

[code removed]

Last edited on by admin
looks like a deja vu.

well instead of having a single iterator itFirst you need a vector of iterators (say matched_vector).

Change line 13 to if(std::find(matched_vector.begin(), matched_vector.end(), itCurrent) == matched_vector.end()) (that tells you that itCurrent has no match)

you need a second loop before line 16 that iterates everything from itCurrent + 1 to end

Store all iterators accordingly (before line 18 matched_vector.push_back(itCurrent)).
Topic archived. No new replies allowed.