I am learning how to use derived classes using inheritance but am so far unable to declare the derived class without error. I have boiled down my code to demonstrate the error I am receiving in the program I am working on
I did not have the <T> on my code, including that fixed my problem.
Having a default constructor was the problem my compiler would have showed next, so thank you for solving my future problem and helping me recognize my current problem!
#ifndef TEST_H
#define TEST_H
#include <string>
#include <iostream>
template <typename T>
class Aaa
{
public:
T var1 { };
void out() { std::cout << var1 << '\n'; };
Aaa(T a) : var1(a) { }
};
template <typename T>
class Bbb : public Aaa<T>
{
public:
Bbb(T b) : Aaa<T>(b) { }
};
#endif
Either way, you need to derive Bbb<T> from Aaa<T>, not Aaa. In your original code (and @Furry Guy's solution) you have duplicate member data (var1 and var2) and you need a default constructor. In my solution, you only have 1 copy of the member data, and you don't need a default constructor.
I retained the member data in the two classes since they might not be duplicates. The derived class might be storing different data from the base class.