Derived class shenanigans

So, I am in a bit of a tizzy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

class Derived:public Base
{
public:
Derived():Base() //unsure of syntax here
{
//initialize some values that were not in base constructor, referencing protected variables in base class
}
}:
int main()

Base ** group;
group = new Base * [number];
group[0] = new Derived(arg 1, arg 2, arg 3, arg 4);


My question:

The derived call in the main with the 4 arguments are the identical 4 arguments the base class constructor fills. It would be the same as if I went new Base(arg 1, arg 2, arg 3, arg 4)

it fills in the exact same data. This is desired. All I want the derived constructor do is fill in NEW data (not taking any new arguments).

How do I get the derived constructor to use the base constructor? Currently the error is "No instance of constructor Derived::Derived matches the argument list.

Last edited on
1
2
3
4
  derived()
    {
        derived::base();
    }
you only overrode the default constructor, you need to override the one with the parameters.
Ok, now getting these errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Derived() : public Base //Here, it says "Expected an identifier" on the closing parenthesis and "expected a ;" on the colon...
{
public:
Derived::Base();
{
//some assignments to protected variables in base class
}

};

int main()
{
group[0] = new Derived(arg 1, arg 2, arg 3, arg 4); //here, derived is underlined and says "incomplete type name not allowed
}





Thanks for your help
Last edited on
You put ( ) after class name. It should be:
 
class Derived : public Base


Also, your constructor doesn't take any arguments and it is defined wrong.
1
2
3
4
Derived()
{
   Derived::Base(); //it should be a function call inside
}

Last edited on
Topic archived. No new replies allowed.