我正在尝试制作井字游戏。我进行了此功能,该功能应该更新板的值(插入“ X”或“ O”),但结构只是不更新,它表明这些值与初始化的值相同。
#include <iostream>
struct Board {//initializes a struct
char A1 = ' ';
char A2 = ' ';
char A3 = ' ';
char B1 = ' ';
char B2 = ' ';
char B3 = ' ';
char C1 = ' ';
char C2 = ' ';
char C3 = ' ';
};
struct Board InputSignInStruct(char num, char letter, struct Board b,char sign) {//a function which is supposed to update values in the struct
if (letter == 'A')
{
if (num == '1')
b.A1 = sign;
if (num == '2')
b.A2 = sign;
if (num == '3')
b.A3 = sign;
}
if (letter == 'B')
{
if (num == '1')
b.B1 = sign;
if (num == '2')
b.B2 = sign;
if (num == '3')
b.B3 = sign;
}
if (letter == 'C')
{
if (num == '1')
b.C1 = sign;
if (num == '2')
b.C2 = sign;
if (num == '3')
b.C3 = sign;
}
return b;
}
int main() {
struct Board b;
char letter,num;
std::cin>>letter>>num;
char sign;
std::cin>>sign;
b = InputSignInStruct(letter, num, b, 'X');//should return the updated struct but it doesent update
}
答案 0 :(得分:3)
您的函数定义是
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
let keys = firstTbaleViewBoatArray[indexPath.row].key
DB_BASE.child("boat").child(keys).removeValue { (error, ref) in
if error != nil {
print("could not delete")
return
} else {
self.firstTbaleViewBoatArray.remove(at: indexPath.row) //out of range error happened here
self.tableView1.deleteRows(at: [indexPath], with: .fade)
self.tableView1.reloadData()
}
}
}
但是你打电话给
$doc = new DOMDocument();
$doc->loadXML($xml);
// convert to xpath
$xpath = new DOMXPath($doc);
// search
$search_results = $xpath->query('//flight//hotel[@id=678]');
您已将struct Board InputSignInStruct(char num, char letter, ...)
和b = InputSignInStruct(letter, num ...)
互换。
答案 1 :(得分:1)
您需要使函数调用值与定义匹配。
更改此:
b = InputSignInStruct(letter, num, b, 'X');/
对此:
b = InputSignInStruct(num, letter, b, 'X');/