cppyy icon indicating copy to clipboard operation
cppyy copied to clipboard

Reset / restart backend state

Open ggoretkin-bdai opened this issue 2 years ago • 1 comments

import cppyy

# Is there something I can put here to ensure that the cling state is reset and not get an error when re-running code?
# SyntaxError: Failed to parse the given C++ code
# input_line_39:2:7: error: redefinition of 'Shape

cppyy.cppdef("""
class Shape {
    public:
        virtual float get_area();
};


class Rectangle: public Shape {
    public:
        float width;
        float height;
        float get_area() {
            return width*height;
        }
};
""")

Is there a way to set gClingOpts->AllowRedefinition (from https://root.cern/blog/cling-declshadow/)?

ggoretkin-bdai avatar Jul 11 '23 19:07 ggoretkin-bdai

Redefinitions are enabled, but only apply to variables, not to classes or functions. There's no current way to reset Cling. You can use namespaces for different versions of a class to co-exist. On the Python side, replacing one by the other works the usual way (all assignments being references).

wlav avatar Jul 11 '23 22:07 wlav