Class inherits a class but can't use/recognize any of base class constructors?

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?
What error message are you getting?

Andy

P.S. There is no such thing as a virtual constructor. And "w/e keyword" ??
Classes are by default private; that could make the constructor private if you don't specify otherwise.
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
they said something about classes not inheriting constructors?

They don't. Compile and see:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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).
Last edited on
Topic archived. No new replies allowed.