I'm trying to use SuperObject in a C++Builder application for JSON marshalling.
SuperObject has some generic functions to help with this:
TSuperRttiContext = class
...
function AsType<T>(const obj: ISuperObject): T;
function AsJson<T>(const obj: T; const index: ISuperObject = nil): ISuperObject;
end;
In the generated .hpp, they appear as this.
class PASCALIMPLEMENTATION TSuperRttiContext : public System::TObject
{
...
template<typename T> T __fastcall AsType(const _di_ISuperObject obj);
template<typename T> _di_ISuperObject __fastcall AsJson(const T obj, const _di_ISuperObject index = _di_ISuperObject());
};
All fine so far. I can compile code like this
TMyObject * myObject = ...;
_di_ISuperObject obj = superRttiContext->AsJson(myObject);
String s = obj->AsString();
But, I can't link it.
[ILINK32 Error] Error: Unresolved external 'System::DelphiInterface<Superobject::ISuperObject> __fastcall Superobject::TSuperRttiContext::AsJson<TMyObject *>(const TMyObject * const, const System::DelphiInterface<Superobject::ISuperObject>)' referenced from C:\FOO.OBJ
Now, this isn't totally unexpected: The Embarcadero DocWiki says this will happen if the template isn't instantiated within Delphi code.
But, here's the problem - TMyObject
is a C++ object descended from TObject
, so I can't see how to instantiate the template from Delphi code.
Any ideas?