- Edited
Does Godot Engine with C ++ support abstract classes?
I made an abstract class in C ++.
The ".h"
// Godot engine C++ Gdnative Estructura de un archivo
#ifndef TESTABTRACTCLASS_H
#define TESTABTRACTCLASS_H
#pragma once
#include <Godot.hpp>
#include <Node.hpp>
namespace godot {
//Testing an abstract class with C ++ for use with GDnative
class TestAbstracClass : public Node {
private:
GODOT_CLASS(TestAbstracClass, Node)
public:
TestAbstracClass();
~TestAbstracClass();
void _init();
void _ready();
static void _register_methods();
protected:
virtual void Walk() = 0; //virtual
virtual void Run() = 0; //virtual
virtual void Attack() = 0; //virtual
virtual void Jump() = 0; //virtual
};
}
#endif
The ".cpp"
#include "TestAbstracClass.h"
using namespace godot;
TestAbstracClass::TestAbstracClass() {}
TestAbstracClass::~TestAbstracClass() {}
void TestAbstracClass::_init() {}
void TestAbstracClass::_ready() {}
void TestAbstracClass::_register_methods() {}
As you can see, the class is abstract because it has 4 pure virtual methods that are going to be defined in the classes that inherit from it.
However I see that it does not compile, it seems that it does not support the abstract data type, that is, this error appears naming all the abstract methods ...
D: \ GODOT ENGINE C ++ PROJECTS \ GodotMatematicalGameCPP \ godot-cpp \ include \ core \ Godot.hpp (153): note: 'void godot :: TestAbstracClass :: Walk (void)': it is abstract
D: \ GODOT ENGINE C ++ PROJECTS \ GodotMatematicalGameCPP \ godot-cpp \ include \ core \ Godot.hpp (171): note: See the reference to creating an instance of the template function "void * godot :: _ godot_class_instance_func <T> (godot_object *, void *) "which is being compiled
with
[
T = godot :: TestAbstracClass
]