I have a class that inherits another class from a different library in a header file. I have one header and three sources. My only error when compiling is that the constructor i'm using for this derived class is that it's not being recognized. Is it possible that this class's constructor had a virtual or w/e keyword that is that makes it so derived classes can't use it?
Hmm, I was just on another site that was api specific and they said something about classes not inheriting constructors? Idk if that's completely true.
BoundTests.cpp: In function ‘int main()’:
BoundTests.cpp:7: error: expected unqualified-id before ‘[’ token
BoundTests.cpp:8: error: no matching function for call to ‘_2de::_2deWindow::_2deWindow(sf::VideoMode, const char [16])’
_2de.hpp:45: note: candidates are: _2de::_2deWindow::_2deWindow()
_2de.hpp:45: note: _2de::_2deWindow::_2deWindow(const _2de::_2deWindow&)
BoundTests.cpp:11: error: ‘_2de::Choice’ is not a class or namespace
BoundTests.cpp:13: error: ‘_2de::SubChoice’ is not a class or namespace
this is the output. It's fricken confusing me. basically My class inherits sf::RenderWindow from SFML with public. Idk that constructor isn't working
class Base
{
protected:
int baseMember;
public:
Base()
{
baseMember = 0;
}
Base(int num)
{
baseMember = num;
}
};
class Derived : public Base
{
};
int main()
{
Derived d1; //default constructor: it works (special case: it was provided, *not* derived)
Derived d2(5); // *compile error* My compiler wonders why I'm invoking the copy constructor with an int
return 0;
}
If you're creating a Derived object instance with a Base constructor, then it won't work. You should give your class a constructor with the same signature as the sf::RenderWindow constructor and simply call the sf::RenderWindow constructor (in an initializer list).