好的,基本上我需要使用 std::transform() 函数。但是,我正在尝试将对象函数作为最后一个参数传递,但它似乎不起作用。
class isprime {
public:
// declares the constructor and the operator() overloading
isprime(){ number = 0, primes.push_back(2);};
bool operator()(int);
private:
// various private functions and variables
int number;
list<int> primes; //creats a list via the stl library
void morePrimes(int); //function to generate more prime numbers
bool it; // Iterator for the morePrimes list
bool primeCheck; // Bool used in the morePrimes function
};
bool isprime::operator()(int number)
{
if(number == 1) //returns false for 1
return false;
if(number > primes.back()){ //Tests to see if the list of primes range would include the number, if not it runs the morePrimes function
morePrimes(number);
}
it = binary_search(primes.begin(),primes.end(),number); //uses stl find to see if the number is in the list of primes.
if(it) //if the returned iterator points to a value = to number then number is prim.
return true;
return false; //returns false if the number wasnt found
};
transform(random_list.begin(), random_list.end(), isprime_list.begin(), test());
上面我已经包括了我用于转换的类、函数和调用。任何人都知道为什么这不起作用?我想不通。