奇怪的C ++语法 [英] Strange C++ syntax
问题描述
我有8年的编码经验,但是我从未见过将运算符[]
作为参数传递给函数定义.
I have 8 years of coding experience, but I have never seen the operator []
passed as a parameter to the function definition.
例如,以下代码(来自开源项目):
For example, the following code (from an open source project):
bree::porder(m_root, [] (treenode* node) { delete node; });
在我的编码生涯中,我始终将[]
定义为运算符重载程序,而不是参数.
Throughout my coding life, I have always defined []
as an operator overloader, not as a parameter.
那么,这种新语法意味着什么?
So what does this new syntax signify?
我正在使用Visual Studio 2003附带的编译器.如何更改上面的代码,使其可以在VS 2003中进行编译?
I am using the compiler that comes with Visual Studio 2003. How can I change the above code so that it will compile in VS 2003?
推荐答案
That is a c++ lambda you could replace the code with a function object of the same definition. The link shows two examples one using Functor and one using a lambda.
这篇关于奇怪的C ++语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!