因为要离开现公司, 两个月前招到一个来接替我的小伙子, 此子只用过 C, 做了半年嵌入式, 我对他进行了两个月的 C++培训, 带着他看 C++ primer 这本书(这本书既厚又杂,想着有我帮着梳理的话亦可事半功倍, 感觉这本书不太好, 但是又没找到可替代的又是中文版的 C++入门书), 让他完成一些编程任务, 帮他 debug 并解惑, 更多的是解释原理: 为什么是这样的.
现在到考核期了, 公司要求用英文出题考核他, 题如下:
C++ Questions
Single Choice
(3 points each, 15 points total)
-
Which one of the following C++ codes is correct C++11 expression?
- [ ] A.
const int i{3.14}; - [ ] B.
int & i = 233; - [ ] C.
const int& i{3.14}; - [ ] D.
constexpr double pi{3.14};
- [ ] A.
-
which one of the following is valid lambda expression usage?
-
[ ] A.
int i = 10; auto f = [](){ return i+1;}; f(); -
[ ] B.
int i = 10; auto f = [](int i){ return i+1;}; f(); -
[ ] C.
int i = 10; auto f = []{ return i+1;}; f(); -
[ ] D.
int i = 10; auto f = [i]{ return i+1;}; f();
-
-
What does public inheritance mean?
- [ ] A. Implementation details
- [ ] B. Private interfaces
- [ ] C. Composition
- [ ] D. Is-a relationship
-
What does private inheritance mean?
-
[ ] A. Implementation details
-
[ ] B. Private interfaces
-
[ ] C. Composition
-
[ ] D. Is-a relationship
-
-
Suppose we have two classes(both with default constructors):
class Base{...};,class Derived: public Base {...};, which one of the following usage is correct?- [ ] A.
Derived* d = new Base; - [ ] B.
Derived* d = new Base{}; - [ ] C.
std::unique_ptr<Base> ptr = std::make_unique<Derived>(); - [ ] D.
std::unique_ptr<Derived> ptr = std::unique_ptr<Derived>(new Base);
- [ ] A.
Answer the following questions
(5 points each, 25 points total)
-
Use
range forsyntax to add 10 to each elements of the followingvector:auto numbers = std::vector<int>{1, 2, 3, 4, 5}; -
Use
std::for_eachto answer the previous question. -
Suppose
Buffer* create_buffer()is some library function to allocate resources, andbool release_buffer(Buffer* buffer)is the counterpart to free the allocated resources, usestd::unique_ptrto manage the resources.(hint: when thestd::unique_ptrobject is out of scope, the allocated resources are automatically released.) -
Suppose
class Objectmust have a copy constructor, a copy assign operator, a move constructor, a move assign operator and a destructor, write down their signatures . -
RAII is a key C++ programming technique, write down your understanding of RAII (not the literal meaning)
我参考当初他问过的问题以及给他的解答出的, 当然考核只是个形式, 所以我直接把题给他先看看, 让他先尝试着做, 结果一题不会! 苦口婆心两个月 == 0.
有一些想法:
- 想 21 天精通 C++, 得参考某张漫画里面来, 一时找不到图了, 就是最后发明时光机穿越回到学 C++第 21 天, 然后捅死自己那张漫画;
- 新同事学习方法很有问题, 每次我跟他讲一些原理的时候让他记一下, 他说这个很显然啊, 没必要记, 然后下次问他相同问题, 对方回答无非是"搞忘了", "你跟我讲过这个吗?" ,根本带不动!
- 不梳理知识, 只在书里面随便勾勾画画, 当然这本书等于没看;
- 题可能出得太难了, 不适合 C++初学者, 但是平时这些主题讲得特别多, 现在看来对方的"嗯嗯, 理解了"明显是在敷衍我了, 其实那根本是在敷衍自己;
- 英文太差, 其实一开始题都没读懂, 我一个个地解释了一遍, 还是不会做;
- 搜索引擎对他来讲是摆设.
- 人不笨, 但是思维方式已经出现严重问题了, 想甩锅给他之前受过的应试教育. 平时给他讲了很多学习方法跟思考方式, 估计也早成耳边风了.
考核肯定是过不了的了, 最后估计会留在公司打杂, 因为最近又招了个新的人, 还没来报道, 看简历是个硕士, 虽然没写过 C++, 但会 python 跟 java, 在学校也搞过正儿八经的研究. 这个带起来应该能很快起飞, 但已经等不到了, 今天是在该公司的最后一天, 只能祝福着这位"带不动同事", 平静地离开了.