Calling a member function

L

Larry

I have the following:


class TZ
{
public:
....
bool operator< ()(const TZ &tz);
....
};

class CL
{
protected:

typedef TZ *PZ;
typedef boost:array<PZ,10000> PZA;

PZA pza;
long pzc; // Number of used elements of pza

.....

bool ZCmp(PZ p1,PZ p2)
{
return p1->a < p2->a;
}

....

void Init()
{
....

std::stable_sort(pza,pza + pzc,ZCmp);

....
}

....

};

I originally tried this with the items of class CL not in a class
and VC was quite happy with it. When I moved things into the CL class
the compiler naturally complained about ZCmp in the stable_sort line
suggesting it needed to be of the &CL::ZCmp form. It is, of course, now
a member function. However, converting to &CL::ZCmp is not sufficient
and the compiler still complains about not being able to deduce the
arguments from the template. I am obviously missing something but I am
too close to it to see. Suggestions?

PZA is not necessarily full so only a partial sort is required hence the
pza,pza +pzc parameters to stable_sort where pzc is index of the last used
array element. There are no empty elements in the range 0 to pzc.

I am using VC9 (VS2008) and Boost 1_54.





--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
 
V

Victor Bazarov

I have the following:


class TZ
{
public:
....
bool operator< ()(const TZ &tz);

If that operator doesn't change the object (the left-hand side), then
the function itself ought to be declared (and defined) as 'const':

bool operator< () const (const TZ &tz);
^^^^^
....
};

class CL
{
protected:

typedef TZ *PZ;
typedef boost:array<PZ,10000> PZA;

PZA pza;
long pzc; // Number of used elements of pza

If the size of the array is limited to 10000, an 'int' would be
sufficient. Or even a 'short'... A better way would be to define the
size in a constant and make 'pzc' to get its type from that constant.
But that could be the next step. Currently a 'long' should be OK.
.....

bool ZCmp(PZ p1,PZ p2)
{
return p1->a < p2->a;

Does class CL have access to members of TZ? If it does not, you should
get an error here.
}

....

void Init()
{
....

std::stable_sort(pza,pza + pzc,ZCmp);

....
}

....

};

I originally tried this with the items of class CL not in a class
and VC was quite happy with it. When I moved things into the CL class
the compiler naturally complained about ZCmp in the stable_sort line
suggesting it needed to be of the &CL::ZCmp form. It is, of course, now
a member function. However, converting to &CL::ZCmp is not sufficient
and the compiler still complains about not being able to deduce the
arguments from the template. I am obviously missing something but I am
too close to it to see. Suggestions?

PZA is not necessarily full so only a partial sort is required hence the
pza,pza +pzc parameters to stable_sort where pzc is index of the last used
array element. There are no empty elements in the range 0 to pzc.

I am using VC9 (VS2008) and Boost 1_54.

See if FAQ 5.8 helps you. Do you know where to find the FAQ?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top