Listing 2. Creating an Accessory Class and a Static Member Function
class Threaded {
public:
Threaded() {};
virtual ~Threaded() {};
static void *entry (void *ptr);
virtual void *run ()=0;
};
void *Threaded::entry(void *ptr){
return reinterpret_cast<Threaded*>(ptr)->run();
}
class CountPrimes : public Threaded {
public:
CountPrimes(long start_, long stop_);
long total();
void *run();
private:
long start;
long stop;
long count;
bool counted;
bool is_prime (long candidate);
};
void *CountPrimes::run(){
long *return_val=new long(total());
return reinterpret_cast<void*>(return_val);
}
Copyright © 1994 - 2019 Linux Journal. All rights reserved.