LearnFrenzy
Sign in Take a free test

Static and Friend Members · Static and Friend MCQ · Question 9

Static members of class template instantiations Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

For template<class T> struct Box { static inline int n = 0; };, do Box<int>::n and Box<char>::n refer to the same variable?

  • A Yes
  • B No – each instantiation is a distinct class with its own static members Correct
  • C Only if both are used
  • D It does not compile
Correct Answer: Option B

That is why CRTP bases can provide a separate counter per derived class.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links