Constructor doesn't work

Hi everybody! I have a little program, but Derived constructor doesn't work. Please, can somebody help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

class Base
{
public:
    Base(int temp) {variable = temp;}
protected:
    int variable;
};

class Derived: public Base
{
public:
    Derived(int temp) {variable = temp;}
};

int main()
{
    Derived d(25);

    return 0;
}
Last edited on
1
2
3
4
5
class Derived: public Base
{
public:
    Derived(int temp) : Base( temp ) {}
};
The other way is to define the derived class as

1
2
3
4
5
6
class Derived: public Base
{
public:
    using Base::Base;   
    Derived() = delete;
};
Thanks for a help
Topic archived. No new replies allowed.