c++ - C++ 表达式在我的类上必须具有类类型
问题描述
我newHTTP
对第 13 行的错误“表达式必须具有类类型”感到非常困惑
#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>
#include <WinHttp.h>
#include "myHTTP.h"
int main()
{
WinHTTP newHTTP();
// error is here
HINTERNET myResponse = newHTTP.httpConnect(L"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
L"http://api",
0,
L"GET");
//
int x;
std::cin >> x;
return 0;
}
我只是不明白我缺少什么,我在 myresponse 上指定了 HINTERNET 并确保 httpConnect 方法返回一个值。有人可以帮忙吗?我的课程代码(当然修剪):
class WinHTTP {
private:
std::string siteUsername, sitePassword;
std::wstring UA, URL;
bool bResult = false;
DWORD dwSize = sizeof(DWORD); // used to handle reading data in bytes
LPSTR pszOutBuffer; // used to Allocate space for the buffer.
DWORD dwDownloaded = 0; // set to null if using asynchronously and use in callback function only
HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL;
public:
WinHTTP(std::string myuser, std::string mypass) : siteUsername(myuser), sitePassword(mypass){
}
// TODO: update to be able to add proxy details either here or before. do check if proxy has been detected in here and open/connect accordingly
HINTERNET httpConnect(std::wstring userAgent, std::wstring myURL, int isHTTPS, std::wstring protocol) {
UA = userAgent;
URL = myURL;
std::wstring acceptTypes = L"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
int portToUse;
if (isHTTPS == 1) {
portToUse = 443;
}
else {
portToUse = 80;
}
//initialize http and return session handle -- use c_str to convert wstring to LPCWSTR
hSession = WinHttpOpen(UA.c_str(),
WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
//make the connection request
if (hSession) {
hConnect = WinHttpConnect(hSession, URL.c_str(), portToUse, 0);
}
else {
printf("error: %d",GetLastError());
}
// open the request - not connected at this point
hRequest = WinHttpOpenRequest(hConnect, protocol.c_str(), NULL, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
if (hRequest) {
return hRequest;
}
else {
printf("error: %d", GetLastError());
return hRequest;
}
}
};
解决方案
如果您调用一个,请添加默认构造函数。我只看到参数化的一个。
推荐阅读
- python-3.x - 使用单个命令运行测试并收集覆盖率报告
- php - MySQL 中的外键约束形成错误:Laravel 迁移
- multithreading - 在 std::lock_guard<> 的声明中添加 const 有什么意义?
- node.js - React 代理使用了错误的 url
- php - 如何检查PHP中的所有参数是否为假?
- r - 在R中将负值转换为零
- powershell - Microsoft 文档给出的 Set-MalwareFilterPolicy 示例失败
- java - 如何获得肥皂身体
- java - 使用 Tomcat 运行带有外部库的应用程序时出现 NoClassDefFoundError
- sql - Amazon Redshift 中的动态合并语句 (upsert)