Files
Obsidian-Main/20.02. CPP/Class template.md

24 lines
371 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
> Class template類別樣板不是類別而是建立類別的方法。
定義類別樣板
```cpp
template <template parameter list>
class ClassName
{
// Template class definition
};
```
`typename`來指定會變動的變數型態,例:
```cpp
template <typename T1, typename T2>
class MyTemplateClass
{
public:
T1 length;
T2 weight;
};
```