C++ Advanced Topics: 10 Questions
- 时间:2020-09-17 11:25:43
- 分类:网络文摘
- 阅读:152 次
Here are the 10 questions to test your C++ advanced topics skills (correct answers are marked in BOLD):
You want to use std::map as a lookup table, but you might have several entries with the same key. You should use:
- std::multimap
- std::map, this isn’t a problem
- std::map with vector instances for the values
- std::duplimap
Which of these is not an advantage of std::string over char* strings?
- move semantics are implemented for you
- memory is automatically cleaned up
- there are less opportunities to code off-by-one-bugs
- strings take up less memory on the free store
When is it a good design to use a raw pointer as a member variable?
- When you are willing to write code to manage the lifetime
- When the compiler will generate lifetime management code for you
- When the pointer is only used to call methods, not for lifetime
- Never
In the statement x = update(b+c,d); which of these is an rvalue?
- x
- b+c
- b+c,d
- d
Some files that include a header to get a definition of a class can instead just use a forward reference. Which of these kinds of code can do that?
- Code that only calls public methods of the class
- Code that accesses methods of the class only through a pointer
- Code that doesn’t call methods or declare instances of the class
- Code that is in a friend class of the class
When should you choose list over vector?
- Never
- When you’ve measured a performance difference in your own application
- When you will insert and delete more often than you will traverse
- When the objects in the container are large
Which of these statements about standard algorithms is true
- They may be slower than code you write yourself
- They may be faster than code you write yourself
- They cannot be faster than code you write yourself
- They are always faster than code you write yourself
The standard vector will use move semantics if possible. Which contained elements can’t be moved unless you write a move constructor and move assignment operator?
- objects with standard vector instances as member variables
- objects with standard unique_pr instances as member variables
- objects with a destructor
- standard string instances
When is the best time to mark a member function as const?
- never
- after it’s tested and working
- before anyone else writes code that calls it
- before you write it
If a lambda captures a local by reference, what bad thing may happen?
- The lambda itself cannot be put into a variable
- The lambda will not be able to change the captured value
- The value may go out of scope before the lambda uses it
- The lambda cannot call a function
–EOF (The Ultimate Computing & Technology Blog) —
推荐阅读:面部出现这些变化则是男人肾虚要进行饮食调理 酱油吃多了会导致皮肤变黑吗?别再被忽悠啦! 健康饮食:人们都说吃了“隔夜菜”致癌,这是真的吗? 豆腐味美又养生,做一道家常菜让你胃口大开 女性在特殊时期饮食需要注意,不能吃这些食物 此菜肴脆嫩爽口肉香浓郁且色香味俱全,为冬季百吃不厌的佳肴 枸杞子吃法正确才能更好吸收营养,但人在出现状况时最好别吃它 土豆是一种非常普通的蔬菜,但其营养保健价值令人难以置信 大家别忘了喝碗营养丰富的腊八粥,它对女性朋友的好处尤其多 经常吃一点柚子好处多,柚子皮的作用也不少,以后别再浪费啦
- 评论列表
-
- 添加评论