C++ String Overriding

13 Jan, 2019 - Notes
// Symbol.h extract
class Symbol {
public:
    virtual std::string render();
    friend std::ostream & operator<<(std::ostream &stream, Symbol &v);
};
// Symbol.cpp extract
#include "Symbol.h"

std::ostream &operator<<(std::ostream &stream, Symbol &v) {
    return stream << v.render();
}

Then:

// Variable.h extract
class Variable: public Symbol {
public:
    std::string name;

    explicit Variable(const char* name);
    std::string render() override;
};
// Variable.cpp
#include "Variable.h"

Variable::Variable(const char* name) {
    this->name = name;
}

std::string Variable::render() {
    return this->name;
}