C++ objects at runtime (was: HI)

Rupert Wood me@rupey.net
Mon Nov 26 04:36:00 GMT 2001

prasad inchal wrote:

One general principle of C++ is to perform as many checks as possible at
compile-time - I don't think it qualifies as 'late-binding' (if you
could even apply that to a language - sounds more like linking to me).

> 1: I want to have C++ to create class objects dynamically, at
>    runtime.

If you mean create new instances of object types that you defined at
compile time, then yes - use the 'new' operator.

If you mean define new object types at run time, then no. I'm not sure
why you'd want to do this anyway. You could, I suppose, hack together a
run-time derivative and overload the virtual functions in a new vtable
but I don't know why you'd want to do this and I don't believe that
there's any support for this in the compiler - what you'd end up with
would be a nasty hack.

>  2: I want to have an interpreter where in I can call C++ member
>     functions directly with the respective obj and parameters.

No, not easily possible. Again, you need intimiate knowledge of the C++
ABI and mangling scheme; you'd need symbol information persisted beyond
the link stage and you'd need assembler chunks to construct the right
call state and make the call.

Hope that helps,

More information about the Gcc-help mailing list