Deduplicate << operator implementation on inheritance I have the following working code:
person.h
#ifndef PERSON_H
#define PERSON_H

#include &lt;iostream&gt;
#include &lt;string&gt;

class Person {
private:
    std::string firstName;
    std::string middleName;
    std::string lastName;

public:
    Person() = default;
    Person (std::string pFirstName, std::string pMiddleName, std::string pLastName);
    Person (std::string pFirstName, std::string pLastName);

    std::string getFirstName();
    void setFirstName(std::string pFirstName);
    std::string getLastName() const;
    void setLastName(std::string pLastName);
    std::string toString() const;

    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; target, Person const &amp; person);
};

#endif

person.cpp
#ifndef __person__
#define __person__

#include &lt;iostream&gt;
#include &lt;string&gt;

#include &quot;person.h&quot;

using std::string;
using std::ostream;

Person::Person (string pFirstName, string pMiddleName, string pLastName)
: firstName(pFirstName), middleName(pMiddleName), lastName(pLastName)
{
}

Person::Person (string pFirstName, string pLastName)
: firstName(pFirstName), middleName(&quot;&quot;), lastName(pLastName)
{
}

string Person::getFirstName ()
{
    return firstName;
}

void Person::setFirstName (string pFirstName)
{
    firstName = pFirstName;
}

string Person::getLastName () const
{
    return lastName;
}

void Person::setLastName (string pLastName)
{
    lastName = pLastName;
}

string Person::toString () const
{
    if (middleName == &quot;&quot;)
        return firstName + &quot; &quot; + lastName;

    return firstName + &quot; &quot; + middleName + &quot; &quot; + lastName;
}

ostream&amp; operator&lt;&lt; (ostream&amp; target, Person const &amp; source)
{
    target &lt;&lt; source.toString();
    return target;
}

#endif

tweeter.h
#ifndef TWEETER_H
#define TWEETER_H

#include &lt;string&gt;

#include &quot;person.h&quot;

class Tweeter
: public Person
{
private:
    static int gid;
    int id;
    std::string twitterHandle;

public:
    Tweeter(std::string pFirstName, std::string pMiddleName, std::string pLastName, std::string pTwitterHandle);
    Tweeter(std::string pFirstName, std::string pLastName, std::string pTwitterHandle);
    std::string toString() const;
    friend std::ostream&amp; operator&lt;&lt; (std::ostream&amp; target, Tweeter const &amp; source);
};

#endif

tweeter.cpp
#ifndef __tweeter__
#define __tweeter__

#include &lt;iostream&gt;

#include &quot;tweeter.h&quot;

using std::ostream;
using std::string;
using std::to_string;

int Tweeter::gid = 0;

Tweeter::Tweeter(string pFirstName, string pMiddleName, string pLastName, string pTwitterHandle)
: Person(pFirstName, pMiddleName, pLastName), id(gid), twitterHandle(pTwitterHandle)
{
    gid++;
}

Tweeter::Tweeter(string pFirstName, string pLastName, string pTwitterHandle)
: Tweeter(pFirstName, &quot;&quot;, pLastName, pTwitterHandle)
{
}

string Tweeter::toString() const
{
    return &quot;[&quot; + to_string(id) + &quot;] &quot; + Person::toString() + &quot; (&quot; + twitterHandle + &quot;)&quot;;
}

ostream&amp; operator&lt;&lt; (ostream&amp; target, Tweeter const &amp; source)
{
    target &lt;&lt; source.toString();
    return target;
}

#endif

As you can see, I have a nearly duplicate implementation for the &lt;&lt; operator in the subclass Tweeter. I had to do that, since, if I just use the &lt;&lt; operator implementation inherited from Person, C++ would silently cast the Tweeter instance as Person as per the operator function's signature and call Person::tostring() instead of Tweeter::toString().
Is it possible to just have one implementation of the &lt;&lt; operator that can be inherited without override and thusly code duplication?
Yes use a virtual print() function.
PS. I would also make the toString use the virtual print function to make it more effecient.
class Person 
{
    // OTHER STUFF

    virtual void print(std::ostream&amp; target = std::cout) const
    {
        target &lt;&lt; firstName &lt;&lt; &quot; &quot;;
        if (middleName != &quot;&quot;) {
            target &lt;&lt; middleName &lt;&lt; &quot; &quot;;
        } 
        target &lt;&lt; lastName;
    }
    std::string toString() const
    {
        std::stringstream  stream;
        this-&gt;print(str);
        return stream.str();
    }

    friend std::ostream&amp; operator&lt;&lt;(std::ostream&amp; target, Person const&amp; person)
    {
        person.print(target);
        return target;
    }
};


class Tweeter: public Person
{
    // OTHER STUFF


    // Don't need this any more: =&gt; std::string toString() const;
    // Don't need this any more: =&gt; friend std::ostream&amp; operator&lt;&lt; (std::ostream&amp; target, Tweeter const &amp; source);

    virtual void print(std::ostream&amp; target = std::cout) const override
    {
         target &lt;&lt; &quot;[&quot; &lt;&lt; to_string(id) &lt;&lt; &quot;] &quot;;
         Person::print(target);
         target &lt;&lt;  &quot; (&quot; &lt;&lt; twitterHandle &lt;&lt; &quot;)&quot;;
    }
};