All pastes #167596 Raw Edit

Stuff

public text v1 · immutable
·published 2006-09-12 03:52 UTC
rendered paste body
Hello Mr. Stroustrup, I have a question regarding C++ that I was not able to find an answer to anywhere else, and since it is mostly a question of your own reasoning in designing the language, I decided I would try asking you.

When you inherit a class, before you can use one of the base methods you have to redeclare it. Why is this necessary in terms of reason? We declare functions with the specifications that they are called by, so that they can be called without knowing the function's definition, isolating compilations, and ultimately decreasing build time. But when you inherit a class, the base class's declaration cannot change, so it seems redundant to redeclare the same method in the derived class when it can be assumed directly from the base class.

Example:

// -----

class base
{
    virtual void method() = 0;
    // ...
};

// I would expect this to be acceptable:

class derived : public base
{
    // ...
};

void derived::method()
{
    // ...
}

// However, you must redeclare "method" in "derived" before you can define it. Like this:

class derived : public base
{
    void method();
};

void derived::method()
{
    // ...
}

// -----

I can think of one reason for this, because the derived method can be re-declared with virtual or not, but it seems to me like one or the other could be defaulted to if that was the only reason.

Thank you,
 Emery De Nuccio