CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #124

Defining get() Outside the Class Template

mediumTemplates

get() is declared inside Box but will be defined outside the class body, where the comment is. Which definition is correct?

📄 Code

1#include <iostream>
2 
3template <typename T>
4class Box {
5 T value;
6public:
7 Box(T v) : value(v) {}
8 T get() const;
9};
10 
11// the definition of get() goes here
12 
13int main() {
14 Box<int> b(42);
15 std::cout << b.get() << "\n";
16 return 0;
17}