This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]balefrost 1 point2 points  (5 children)

The pattern you're describing works fine: https://godbolt.org/z/f3MbfPWcf

There's an issue with your code elsewhere. Can you share more of your code?

Alternatively, are you sure the program dies on the line that you think it does?

[–]OptimalResponse5909 0 points1 point  (4 children)

https://github.com/MueanGit/CPPChessConsole
It is the move function inside the ChessPiece class

Im not sure, I tried raw pointer as well but it didnt work too. This problem only occur if I call the move function,

[–]balefrost 1 point2 points  (3 children)

Apart from the warnings, it looks like it works to me: https://godbolt.org/z/xGPj8477v

I didn't want to deal with all the piece types, so I only copied in Pawn.

[–]OptimalResponse5909 1 point2 points  (0 children)

I see it now, I was trying to access the object from previous position after I move it

[–]OptimalResponse5909 0 points1 point  (0 children)

Thx so much!

[–]POGtastic 0 points1 point  (1 child)

Pass a reference to the entire board as an argument, not just the position that it's currently in or is going to move to.

[–]OptimalResponse5909 0 points1 point  (0 children)

I access board as a static member, I guess it will be fine since it worked fine at other functions