In the test.cpp file, I have the following:
template <typename T>
class A
{
public:
A(int a){};
virtual ~A();
private:
};
class B : public A<int>
{
public:
B(int a):A(a){};
virtual ~B();
private:
};
int main()
{
return 0;
}
When I compile it, I get the following:
jason@jason-linux:~/Documents/ECLibrary$ g++ -g -Wall -Wextra -pedantic-errors test.cpp -o tdriver
test.cpp: In constructor βB::B(int)β:
test.cpp:14: error: class βBβ does not have any field named βAβ
test.cpp:14: error: no matching function for call to βA<int>::A()β
test.cpp:5: note: candidates are: A<T>::A(int) [with T = int]
test.cpp:3: note: A<int>::A(const A<int>&)
I do not need a default constructor for my base class, as it does not make sense in my code. I just want my derived class to execute the called constructor of the base class and do some extra construction for the extra material in the derived class. I really don't know why it is trying to call the default constructor of the base class when I try to explicitly call the alternative constructor. Did I miss something?
thank
source
share