In my contract I have a data structure that involves a node struct and a LeafNode and InnerNode struct that inherit from node.
struct node {
...
virtual string to_string() const {
string str("node");
...
return str;
}
};
struct LeafNode : public node {
...
virtual string to_string() const {
string str("LeafNode");
...
return str;
}
};
struct InnerNode : public node {
...
virtual string to_string() const {
string str("InnerNode");
...
return str;
}
};
Assuming I have an initialized node* nodeptr;
:
When calling eosio::print(nodeptr->to_string());
, I want it to call the child's to_string() method if the nodeptr is holding a LeafNode or InnerNode struct instead of just calling the base node::to_string()
method.
In vanilla C++, this can be done using the virtual
keyword. However, after adding it to my struct methods as shown above, I run into the following error:
Error 3070002: Runtime Error Processing WASM
Error Details:
eos-vm system failure
pending console output: ...
Is this because the virtual
keyword is not allowed in EOSIO C++? Or is there something else going on here?