14. The Final Quiz
Check your knowledge from this mini-book!
1. Which C++ Standard did add in-class default member initializers?
- C++98
- C++11
- C++14
- C++17
2. Can you use auto type deduction for non-static data members?
- Yes, since C++11
- No
- Yes, since C++20
3. Do you need to define a static inline data member in a separate cpp file?
- No, the definition happens at the same place where a static inline member is declared.
- Yes, the compiler needs the definition in a cpp file.
- Yes, the compiler needs a definition in all translation units that use this variable.
4. Can a static inline variable be non-constant?
- Yes, it’s just a regular variable.
- No, inline variables must be constant.
5. Consider the following code:
struct S {
int a { 10 };
int b { 42 };
};
What’s the output of the following line?
S s { 1 };
std::cout << s.a << ", " << s.b;
1, 010, 421, 42
6. Consider the following code:
class C {
C(int x) : a(x) { }
int a { 10 };
int b { 42 };
};
C c(0);
More questions available in the full version of the book.