Defined in <plugin/PluginRegister.hh>.
#define REGISTER( CLASS, BASE )
#define REGISTERBYNAME( NAME, CLASS, BASE )
Register CLASS (which must derive from BASE and be default-constructible) so that BASE::create(key) returns a new CLASS.
REGISTER(Circle, Shape)— key is"Circle"(the stringised class name).REGISTERBYNAME(rounded, Circle, Shape)— key is"rounded".
REGISTER(C, B) is exactly REGISTERBYNAME(C, C, B).
Requirements
CLASSis defined (complete type) at the point of the macro.CLASShas an accessibleCLASS()default constructor.BASEhas a catalog — some TU ranCREATECATALOG(BASE).
Placement
File scope, in the plugin's .cpp, once per key. Not in a header (it would register once per including TU — harmless but pointless — and pollute every TU's anonymous namespace).
Example
// Square.cpp → libSquare.so
#include "Shape.hh"
#include <plugin/PluginRegister.hh>
namespace plugin::example {
class Square : public Shape {
unsigned int size = 0;
public:
Square() = default;
void setSize( unsigned int v ) override { size = v; }
unsigned int getSize() const override { return size; }
void printOn( std::ostream& os ) const override { os << "Square a:" << size << '\n'; }
};
REGISTER( Square, Shape ); // key "Square"
}
Host side:
Shape::load( "./libSquare.so" );
auto sq = Shape::create( "Square" ); // new plugin::example::Square
Notes
- The key is a string, not a symbol —
create("Square"), and it is case-sensitive. - Registering two classes under one key: the DSO loaded last wins (
insertoverwrites). Use distinct or namespaced keys. - A class needing constructor arguments uses
REGISTER_WITH_CONFIGinstead. - To also expose the class under a second name, add
REGISTERAS.

