I’m new to C++ coming from C# so I’m not too confident on memory stuff, I think I’m getting some undefined behaviour issues when trying to use my class (feel free to correct me if I’m wrong) and I don’t know why. If I put std::cout statements at the end of the Initialise() function it changes the values. My suspicion is the Piece class deleting things in the Initialise() function, but I have no idea how to stop that.
(Cube class is just two std::arrays in a struct) I had a look at the other question asked about undefined behaviour but couldn’t infer what my issue was. Let me know if more information is needed.
Thanks for reading.
// includes
// below are parts of the Manip class
std::array<Piece, 8> * _corners; [text]
std::array<Piece, 12> * _edges;
Manip::Manip(Cube* state)
: _corners(state - > corners), _edges(state - > edges) {}
// functions
// as I don't know what functions are causing the issue, I'll include a snip from all relevant ones
std::string Manip::EnumSwitcher(Colour cn) {
switch (cn) {
case Colour::w: return "W";
// more cases
default: return "";
}
bool Manip::ContainsCorner(Location l, char c) {
switch (l) {
case Location::URF:
// more cases
return EnumSwitcher(l).find(c) != std::string::npos;
default: return false;
}
void Manip::Initialise() {
// basically just a lot of
_edges[i] = Piece(...)
_corners[i] = Piece(...)
}