cppyy
cppyy copied to clipboard
Reset / restart backend state
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/)?
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).