'error: type ‘class’ is not a direct base of ‘class’
I haven't been able to find an answer that relates specifically to my question. It's a bit of a "strange" case in terms of what I've seen.
So I have a class Child2
that inherits from Child1
that in turn inherits from the Parent
. The Parent
doesn't have a constructor.
Here is how I inherit:
Child1.h:
class Child1 : virtual public Parent
This is the function that I want to call from Child2
's constructor:
void Child1::foo(unsigned int i)
{
// ...
}
Child2
Child2::Child2() : Child1()
{
foo(10);
}
There are no functions called foo()
in Child2
so there shouldn't be any ambiguity if I understand correctly.
However, I encounter this error:
Child2.cpp: In constructor ‘Child2::Child2()’: Child2.cpp:12:28: error: type ‘Child1’ is not a direct base of ‘Child2’ Child2::Child2() : Child1()
Child1
's constructor is working, so I've left it out. I'm not certain if it is important in this case.
Solution 1:[1]
Check if your Child2 class is declared as a child of Child1. Something like:
class Child2 : Child1
{....}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Magnus |