WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! ----------------------------------------------------- THIS DOCS ARE OUTDATED! I have no time to write down precise docs, so please be patient. ----------------------------------------------------- Have you read readme.txt and versions.txt already ? This file describe how to use C++ with DLM engine. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DLM engine support all common C++ mechanisms, like inheritance, virtual functions, etc. It doesn't require any special syntax. You can use static class instances, dynamic objects (via new and delete), and so on. But in some situations DLM engine will not have enough information to succesfully manage your programm if you will not follow some rules, described below. You also must either auto-load CPP.DLM or load it explicitly in DLM's constructor(). What to have in mind, while using DLMs and C++ : 1. Avoid using inline methods and NEVER use inline constructors. They will possibly not work in some situations. 2. Static objects are created AFTER call to constructor(), so don't use them in constructor. Functions with `constructor' attribute are called like static object's constructors ... 3. If you are using NAMED CLASSES feature (later about it) NEVER call Named New from the same file, where constructor is DEFINED. Named New will surely fail in this case and produce SIGSEGV... SUMMARY : To have less trouble with C++ use the following scheme in defining classes : 1. Create class declaration and put in .h file 2. Create SEPARATE file, in which ONLY ONE class will be DEFINED. NAMED CLASS - what the beast is it ? DLMs give your unique feature - create a instance of class if you have the following information : 1. You know it's name as a string (char *) 2. You know (i.e. have a DECLARATION of) the class, which is higher in the hierarhy (i.e. any of parent class). You will need this to able to call virtual functions and construct objects. 3. Someone who knows (have a DECLARATION of) this class used special macro to make this class available for others. The syntax is the following : In the EXPORTER module, i.e. where the class was DEFINED. DLM_EXP_NAMEDCLASS(class_identifier) This one is needed to obtain sizeof(class_identifier) at run-time. In the IMPORTER module, i.e. where you want to create instance of such class. DLM_USE_NAMEDCLASS /* No name here! This one allows to use any of them */ To create instance : new("class_identifier") Known_Base_Class_identifier( parameters ); This command will call class_indetifier's (NOT Base's!) constructor with the given parameters. It's obvious, that you must HAVE constructor with such prototype. ============================================================================ Example of using NAMED CLASSES : //------------------------------------------------------------ // FILE test.cc //------------------------------------------------------------ #include #include "dlmlib.h" int constructor() // This one is called after DLM was loaded { Load("base.dlm"); // Here are definitions of Base class members, see below. return LoadDLM("cpp.dlm"); // Must be loaded to use new and other }; DLM_USE_NAMEDCLASS // This file will create Named Classes class Base { // Base class DECLARATION int i; public : Base(int); virtual ~Base(); virtual void f(); }; // Derived class DEFINITION. This one will be Named Class. class Derived : public Base { public : Derived(int); virtual ~Derived(); virtual void f(); }; ....... // here are definitions of Derived members ....... // Base members MUST be defined in SEPARATE file!!!! DLM_EXP_NAMEDCLASS(Derived) // This file is also EXPORTER // of Named Class `Derived' int main() { Base *pb,*pd; pb=new Base(10); // Create an instance of Base. Nothing unusual. pb->f(); // Base::f() pd=new("Derived") Base(4); // Create an instance of Derived. // Actually Derived(4) will be called. pd->f(); // Derived::f() delete pd; // Destructors are virtual so Derived::~Derived delete pb; // Base::~Base };