C++ typedef error
C++ typedef error
bool CInetWrapper::OpenFtpConnection (LPCTSTR lpszServerName)
{
// internetconnect(inet_open,'ftp.site.ru',port,'login','pass',INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
if (OpenInternet() && m_hConnection == NULL)
// (HINTERNET,LPCSTR,INTERNET_PORT,LPCSTR,LPCSTR,DWORD,DWORD,DWORD);
typedef HINTERNET (__stdcall* InternetConnect_)(HINTERNET,LPCSTR,INTERNET_PORT,LPCSTR,LPCSTR,DWORD,DWORD,DWORD);
InternetConnect_ ic = (InternetConnect_)helper.GetProcAddressEx("wininet.dll", "InternetConnectA");
m_hConnection = ic(
m_hInternet,
lpszServerName? lpszServerName:
m_lpszServerName? m_lpszServerName: "localhost",
INTERNET_DEFAULT_FTP_PORT,
m_login,
m_password,
INTERNET_SERVICE_FTP,
0,
0);
return CheckError(m_hConnection != NULL);
}
和编译器说:1> ------构建开始:项目:klstart,配置:调试Win32 -------1> httpreader.cpp1> c: u admin Visual Studio 2010 Projects klstart klstart klstart httpreader.cpp(100):错误c2065:'Internet Conconnect_'':undeclared标识符1> c: u admin Visual Studio 2010 Projects klstart klstart klstart httpreader.cpp(100):错误c2146:语法错误:缺失';';''在标识符"助手"之前我写错了什么?
您忘了将if
的真实分支包装到复合语句中。
基本上,问题与此代码
中的问题相同if (some_condition)
typedef int MyType;
MyType i; // ERROR: `MyType` is undeclared identifier
...
在上面的简单示例中,虚构的"作者"想这样做
if (something)
{
typedef int MyType;
MyType i;
...
}
,但他忘了把这些{}
放在那里,最终得到了完全不同的东西。您在代码中犯了同样的错误。
由于您没有在if
之后创建复合语句(使用{}
),该 if
的真实分支中唯一包含的部分是您的typedef
,而没有其他内容。该分支带有孤独的typedef
是一个单独的本地范围,该范围在if
之后立即结束。这意味着在您的if
打字后InternetConnect_
不再知道。
将您的typedef
放在if
之前,或将真分支包装到一对{}
中。
尝试使用#include <cstdlib>
或尝试使用struct,更简单易于遵循,错误的机会更少。
相关文章:
- C++:TypeDef使用元组
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 为什么在使用typedef时类推导指南会失败
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- 尝试根据类中 typedef 的存在来专门化模板函数
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 如何重新定义MPI_FLOAT,MPI_DOUBLE以 typedef 的方式
- typedef 枚举和枚举类有什么区别?
- 在类模板中使用 typedef 时出错
- 模板类中的 typedef 语句
- C++ typedef error