FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

initializer from class fcf::TypeInfo

Property: initializer

Type: fcf::TypeFactoryBase*

Class: fcf::TypeInfo

Package: fcfBasis

File: bits/PartType/TypeInfoDefinition.hpp

Available from version: 1.0.1

Factory used to create/destroy instances of this type

Example:

#include <iostream> #define FCF_BASIS_IMPLEMENTATION #include <fcfBasis/basis.hpp> int main() { const fcf::TypeInfo* ti = fcf::Type< std::string >().typeInfo(); // When passed a null pointer, // the creation function allocates memory from // the heap using the new char[sizeof(Ty)] operator. void* ptr = (char*)ti->initializer->create(nullptr); *((std::string*)ptr) = "Test string"; std::cout << "Data: " << *((std::string*)ptr) << std::endl; // We call the destructor for the pointer. ti->initializer->destroy(ptr); // Freeing the allocated memory. // Similar to the call: delete[] static_cast<char*>(ptr); fcf::TypeFactoryBase::deallocate(ptr); return 0; }

Output:

Data: Test string