| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
 本帖最后由 cjiang3 于 2021-6-24 23:00 编辑  
 
情况1: 目前在法国读博, 面一家实习单位 ,面试题 没做出来, 耿耿于怀 ,虽然失败了 , 但题目还在 
         (ta(某法国HR)给我讲了一个很大的故事,image 的stream processing 要确保同步, 实时什么的), 但关键不在这里, 
           他从项目里抠了一个代码,(我从 #ifndef RunTests 看出来的) , 就下面代码, 全部, 在没有上下文和需求的情况下, 很难做出来,原题是要实现todo里的内容,10个小需求, 确保数据流。。。。。。 
            介绍一下自己, 本人不是学渣, 有着多年C/C++, python 经验,opencv , ros方向,但看到这题后懵了,  
 
 
本体集成了 ,container , iterator , template , 确实是项目中抠出来的代码 ,理解起来就很费劲 ,我把原题需求删了,只要大家回答我下面的问题 ,自己也会看一些 overstack上别人的解释,但觉得有必要这么复杂吗,(正因为,是项目源代码才觉得没老外这么写是有它的意义的),当然也不排除为了测试而测试, 把简单的东西搞复杂。。。 
 
 
我的问题 :    const F1& f1, const F2& f2 ,看样子是传函数指针 ,      但传入的是 
         
“ 
        [](const Event& e){ 
                std::cout << e.t << " [" << e.x << "," << e.y << "]" << std::endl; 
        }   
” 
 
如何解释, ([] 是震惊到我的地方,之前没遇见过) 
 
#include "stdafx.h" 
#include <iostream> 
#include <vector> 
#include <stdexcept> 
 
struct Event { 
        int x, y;             //position 
        unsigned long long t; //timestamp 
}; 
 
template <typename F1, typename F2> 
void iterate(const std::vector<Event>& first_stream, const std::vector<Event>& second_stream, const F1& f1, const F2& f2) { 
        // TODO 
        //throw std::runtime_error("Implement me"); 
} 
 
#ifndef RunTests 
int main(int argc, char* argv[]) { 
        std::vector<Event> first_stream{ Event{ 0, 1, 1 }, Event{ 0, 2, 2 }, Event{ 0, 3, 4 } }; 
        std::vector<Event> second_stream{ Event{ 1, 0, 1 }, Event{ 2, 0, 3 }, Event{ 3, 0, 4 } }; 
        iterate(first_stream, second_stream, 
                [](const Event& e){ 
                std::cout << e.t << " [" << e.x << "," << e.y << "]" << std::endl; 
        }, 
                [](const Event& e1, const Event& e2) { 
                std::cout << e1.t << " [" << e1.x << "," << e1.y << "] [" << e2.x << "," << e2.y << "]" << std::endl; 
        } 
        ); 
 
        getchar(); 
} 
#endif |   
 
 
 
 |