我刚刚在OOP类中了解了多态性,并且我很难理解抽象基类是如何有用的.
抽象类的目的是什么?定义一个抽象基类提供了什么,而不是通过在每个实际类中创建每个必需的函数来提供?
我仍然坚持如何通过cURL将文件上传到HDFS。我之前曾在cURL CLI上尝试过此方法,但它确实有效,但是当我尝试制作运行相同命令的PHP代码时,它不想上传。
这是命令:
curl -i -X PUT -T "c:/xampp/htdocs/experiment/csv.php" "http://123.123.78.9:14000/webhdfs/v1/user/flume/test2?op=CREATE&buffersize=1024&user.name=flume&blocksize=1048576&overwrite=false&data=true&permission=755" --header "Content-Type: application/octet-stream"
Run Code Online (Sandbox Code Playgroud)
这是PHP代码:
function call_curl($headers, $method, $url, $data)
{
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
switch($method) {
case 'GET':
break;
case 'POST':
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
break;
case 'PUT':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
break;
case 'DELETE':
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
return $response;
}
$header …Run Code Online (Sandbox Code Playgroud) C\C++是否支持回调函数的机制?以及如何创建它?我写了几个代码,用C++创建回调函数但是失败了..
#include<iostream>
using namespace std;
void callee()
{
printf("callee\n");
printf("calleeeeeeeeee\n");
}
void callback(void* func)
{
printf("callback\n");
}
int main()
{
void (*call)(void*);
void (*call2)(void);
call2 = &callee;
call = &callback;
call((void*)call2);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)