我一直想知道为什么你不能使用本地定义的类作为STL算法的谓词。使用本地类与STL算法
在这样的问题:Approaching STL algorithms, lambda, local classes and other approaches,BubbaT提到说,“由于C++标准禁止本地类型用作参数”
示例代码:
int main() {
int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
std::vector<int> v(array, array+10);
struct even : public std::unary_function<int,bool>
{
bool operator()(int x) { return !(x % 2); }
};
std::remove_if(v.begin(), v.end(), even()); // error
}
有谁知道在标准是限制吗?禁止地方类型的理由是什么?
编辑:由于C++ 11,它是合法使用本地类型作为模板参数。
我知道,但我想知道在哪里可以看到我能理解为什么。你有没有参考标准? – 2009-04-12 23:16:57
你是指14.3.1.2,“模板类型参数”? – greyfade 2009-04-12 23:19:12