lundi 26 novembre 2018

C++ cannot declare variable var to be of abstract type Type1

I created a base class with two pure virtual functions. Each subclass overrides and implements one of the virtual functions that belong to base class.

Compilation fails in main,

saying cannot declare variable ‘rr’ to be of abstract type ‘Type1Renderer’

What causes this error and how can I fix this?

#include <iostream>
#include <string>
#include <vector>
#include <memory>


using namespace std;

#include <string>
#include <iostream>

struct TypeRenderer {
    virtual float render_type_1 (float v) = 0;
    virtual std::string render_type_2 (std::string& s) = 0;
};


struct Type1Renderer : TypeRenderer {

    float render_type_1 (float v) override {
        std::cout << "render type 1 with : " << v;
        return v;
    }
};

struct Type2Renderer : TypeRenderer {

    std::string render_type_2 (std::string& v) override {
        std::cout << "render type 1 with : " << v;
        return v;
    }
};


int main()
{
    Type1Renderer rr;

}

Aucun commentaire:

Enregistrer un commentaire