I created an abstract class and a concrete subclass:
//bca.h
#include <string>
class bca {
public:
virtual std::string get_virtual_year() const = 0;
};
//bca_interface.h
#include "bca.h"
class bca_interface : public bca {
public:
std::string get_virtual_year() const override;
};
//bca_interface.cpp
#include "bca_interface.h"
std::string bca::get_virtual_year() const override {
return "";
}
When I compile bca_interface.cpp
with g++, I get:
error: virt-specifiers in ‘get_virtual_year’ not allowed outside a class definition
std::string bca::get_virtual_year() const override {
The error says it all:
error: virt-specifiers in ‘get_virtual_year’ not allowed outside a class definition
You cannot put a virt-specifier (override
and final
) outside of a class definition. You only put that specifier on the function declaration within the class definition. The same is true for, e.g., explicit
, static
, virtual
, ...
Where you have it in the header is correct. In your source, just remove it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With