0

I am a newbie to C++ and am self-learning the databases course at CMU. In the second programming project, we implement a B+ tree index. We have a BPlusTreePage class which has two children class BPlusTreeInternalPage and BPlusTreeLeafPage. The way the skeleton code handles generic class confuses me.

In b_plus_tree_internal_page.h:

template <typename KeyType, typename ValueType, typename KeyComparator>
class BPlusTreeInternalPage : public BPlusTreePage {...};

In b_plus_tree_internal_page.cpp:

...
// valuetype for internalNode should be page id_t
template class BPlusTreeInternalPage<GenericKey<4>, page_id_t, GenericComparator<4>>;
template class BPlusTreeInternalPage<GenericKey<8>, page_id_t, GenericComparator<8>>;
template class BPlusTreeInternalPage<GenericKey<16>, page_id_t, GenericComparator<16>>;
template class BPlusTreeInternalPage<GenericKey<32>, page_id_t, GenericComparator<32>>;
template class BPlusTreeInternalPage<GenericKey<64>, page_id_t, GenericComparator<64>>;

I'm wondering what does these lines starting with template class do? In my understanding, the code should just work without those lines, but I'm not sure if I'm correct. Thanks for helping!

Zacchaeus
  • 111
  • 1
  • 7
  • 4
    It's called explicit template instantiation. Check out *[Class template](https://en.cppreference.com/w/cpp/language/class_template)* and *[Explicit template instantiation - when is it used?](https://stackoverflow.com/questions/2351148/explicit-template-instantiation-when-is-it-used)* – Captain Obvlious Jan 09 '23 at 06:45
  • Thanks! That really clears my confusion. – Zacchaeus Jan 09 '23 at 06:48
  • (out of scope): A strange program of learning the C++ language -- in the second project, the study of templates is already underway... – Serge Roussak Jan 09 '23 at 06:49
  • 1
    @SergeRoussak It's a database course, not C++ course. – VLL Jan 09 '23 at 06:54

0 Answers0