XCode 10.1(默认编译器)无法编译以下代码
<?php
// load database connection script
include("database_connection.php");
/*
* Tutorial: PHP MySQL Shopping cart
*
* Page: Application library
* */
class ShopingCart
{
protected $db;
function __construct()
{
$this->db = DB();
}
/**
* get products list
*
* @return array
*/
public function getProducts()
{
$query = "SELECT * FROM `entertainment`";
if (!$result = mysqli_query($this->db, $query)) {
exit(mysqli_error($this->db));
}
$data = [];
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
}
return $data;
}
/**
* get given product details
*
* @param [integer] $id
* @return array
*/
public function getProductDetails($id)
{
$id = mysqli_real_escape_string($this->db, $id);
$query = "SELECT * FROM `entertainment` WHERE `id` = '$id'";
if (!$result = mysqli_query($this->db, $query)) {
exit(mysqli_error($this->db));
}
$data = [];
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$data['id'] = $row['id'];
$data['title'] = $row['title'];
$data['price'] = $row['offer_price_corporate_artist'];
$data['quantity'] = 1;
}
}
return $data;
}
/**
* Add new product into the cart
*
* @param [integer] $id
* @return void
*/
public function addToCart($id)
{
$product = $this->getProductDetails($id);
$isFound = false;
$i = 0;
if (!isset($_SESSION['shopping_cart']) || count($_SESSION['shopping_cart']) < 1)
{
$_SESSION['shopping_cart'] = array(0 => $product);
} else {
foreach ($_SESSION['shopping_cart'] as $item) {
$i++;
foreach ($item as $key => $value) {
if ($key == "id" && $value == $id) {
array_splice($_SESSION['shopping_cart'], $i - 1, 1, array([
'id' => $item['id'],
'title' => $item['title'],
'price' => $item['offer_price_corporate_artist'],
'quantity' => $item['quantity'] + 1,
]));
$isFound = true;
}
}
}
if ($isFound == false) {
array_push($_SESSION['shopping_cart'], $product);
}
}
}
/**
* remove existing product from the cart
*
* @param [integer] $id
* @return void
*/
public function removeProductFromCart($id)
{
unset($_SESSION['shopping_cart'][$id - 1]);
}
}
?>
错误代码在下面
Scanner sc = new Scanner(System.in);
String input = sc.next();
文件扩展名为 .mm (默认-Objective C ++)。当我将扩展名更改为 .m (默认-目标C)时,所有内容均可正确编译。对我来说,这是不合适的,因为我使用的是C ++ / Objective C混合源代码,并且我打算在文件中包含C ++头文件。
据我了解,这是一个编译器错误。它将设置器视为C ++ template <>。有什么解决方法吗?我可以告诉编译器将该行视为纯Objective C代码吗?