错误: VS2019 类成员函数访问其类的私有变量, CPP文件定义类成员函数, 里面引用H文件的类成员变量
LNK2019 指infoSet device deviceIndex valid;这些引用了无定义外部符号,怎解决
Win32Etor.h 定义如下:
class Win32PForUsb
{
public:
Win32PForUsb(void);
~Win32PForUsb(void);
bool next();
void getPath(std::string &str);
void FreeWin32Entor(void);
std::string getType();
private:
HDEVINFO infoSet;
SP_DEVINFO_DATA device;
DWORD deviceIndex;
DWORD typeIndex;
bool valid;
};
Win32Etor.cpp 定义如下:
.......
#include "Win32Etor.h"
DEFINE_GUID(GUID_DEVINTERFACE_DEVICE, 0x28D , 0x5A , 0x111, 0xAE, 0x5B, 0x00, \
0x00, 0xF8, 0x03, 0xA8, 0xC2);
Win32PForUsb::Win32PForUsb(void)
: valid(false), deviceIndex(0)
{
memset(&device, 0, sizeof(device));
device.cbSize = sizeof(device);
infoSet = ::SetupDiGetClassDevsW(
&GUID_DEVINTERFACE_DEVICE,
nullptr,
nullptr,
DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (infoSet == INVALID_HANDLE_VALUE) {
OutputDebugStringA("CPSDK can't open object\n");
}
}
把 infoSet
写成
this->infoSet 看看呢
代码本身没有看到什么问题,是不是还有别的重名的变量