Thx for your replies. I noted that the example you cited was culled from the
qsort function page on here with the
array changed to a
vector.
Let me be more specific now with my problem.
I have a class
bookType roughly defined as shown below, followed by a skeletal function
main():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
class bookType
{
public:
fn 1;
fn 2;
.
.
.
fn n;
private:
int a;
int a[4];
double d;
string s;
};
int main()
{
vector<bookType> vec (10);
qsort(vec, 10, sizeof(bookType), myCompare);
}
|
I successfully loaded data from a text file into
vec
and I do not have a problem with the
myCompare
function. What the compiler flagged was the first argument of the qsort function, saying:
cannot convert `std::vector<bookType, std::allocator<bookType> >' to `void*' for argument `1' to
`void qsort(void*, size_t, size_t, int (*)(const void*, const void*))' |
Qn 1: Why is this so since, in a way,
vec
which is the name of the vector object could be viewed as a pointer like
values
is in the example on the
qsort page?
Qn 2: Since I have a compound data type, in contrast to the fundamental data type used in the example, would I run into problems with the
sizeof()
operator?