I'm new to C++ and am trying to figure out how to use templates to build a hierarchy of classes of specific types for polymorphism. I know how to do this in Java pretty easily with generics. I'm sure this has been asked before, but I simply don't know what terms to use to search for what I want in C++.

I want to be able to use a base class that I've created using a combination of objects made up of the very specified classes defined below as `Derived_1` and `Derived_2`, each of which extend from a class named `Base`. However, I get a compiler error saying I need to declare the type? What syntax do I use to indicate that this `z` vector, used in the implementation, could be made up of any combination of classes that extend from `Base`?

Here is what I have so far, which I think is mostly correct when it comes to declaring the base class and the classes that extend that base class:

base\_types.h
-------------

```cpp
template <typename T>
class Base {
public:
    Base<T>(size_t a, T b) :
            m_a(a),
            m_b(b) {
    }

    T getB() const;

    size_t m_a;
    T m_b;
};

// specific kind of Base that uses bool
class Derived_1 : public Base<bool> {
    Derived_1(uint32_t a);     // second parameter is unused, is assumed to be "true"
    bool getB();
};

// specific kind of Base that uses size_t
class Derived_2 : public Base<size_t> {
    Derived_2(uint32_t a, size_t b);
    size_t getB();
};

```

### base\_types.cpp

```cpp
Derived_1::Derived_1(uint32_t a) : Base(a, true) { }      // second parameter is unused, is assumed to be "true"

bool Derived_1::getB() { return m_b; }

Derived_2::Derived_2(uint32_t a, size_t b) : Base(a, b) { }

bool Derived_2::getB() { return m_b; }

```

### impl\_types.h

```cpp
#include "base_types.h"
#include <vector>

class Foo {
public:
    Foo(
        size_t y,
        const std::vector<Base>& z);      // Error: Use of class template 'Base' requires template arguments
};

```

### impl\_types.cpp

```cpp
class Foo {
public:
    Foo(
        size_t y,
        const std::vector<Base>& z) :      // Error: Use of class template 'Base' requires template arguments
            m_y{y},
            m_z{z};
};

```

For reference, here's the Java implementation of what I want to do:

```java
// Base.java
class Base<T> {
    int m_a;
    T m_b;

    Base(int a, T b) {
        m_a = a;
        m_b = b;
    }

    T getB() {
        return m_b;
    }
}

```

```java
// Derived_1.java
class Derived_1 extends Base<Boolean> {
    Derived_1(int a, Boolean a) {
        super(a, b);
    }

    Boolean getB() {
        return m_b;
    }
}

```

```java
// Derived_2.java
class Derived_2 extends Base<String> {
    Derived_2(int a, String b) {
        super(a, b);
    }

    String getB() {
        return m_b;
    }
}

```

```java
// Main.java
public class Main {

    public static void main(String[] args) {
        List<Base> baseList = new ArrayList<>();
        baseList.add(new Derived_1(1, true));
        baseList.add(new Derived_2(2, "foo"));

        for(Base o : baseList) {
            System.out.println(o.getB());
        }
    }
}

```