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 #122

A Size as a Template Parameter

mediumTemplates

N is a non-type template parameter: a value instead of a type. Which statement is true?

📄 Code

1#include <iostream>
2 
3template <typename T, int N>
4class Buffer {
5 T data[N] = {};
6public:
7 int size() const { return N; }
8};
9 
10int main() {
11 Buffer<int, 4> a;
12 Buffer<int, 8> b;
13 std::cout << a.size() << " " << b.size() << "\n";
14 return 0;
15}