简体   繁体   English

非法使用此类型作为表达式(错误)C++

[英]illegal use of this type as expression (error) C++

The most recent file I've added to my VC++ 2010 project is suddenly giving me errors about the data types.我添加到我的 VC++ 2010 项目中的最新文件突然给我关于数据类型的错误。 After doing a bit of searching, this error seems to be common in C code but I'm using C++ (and yes, my file extension is correct).经过一番搜索,这个错误似乎在 C 代码中很常见,但我使用的是 C++(是的,我的文件扩展名是正确的)。 My BUFFER class still works fine in all my other files and if I comment those out, it throws the same errors about the windows UINT types as well.我的 BUFFER class 在我的所有其他文件中仍然可以正常工作,如果我将它们注释掉,它也会引发关于 windows UINT 类型的相同错误。

Btw, this is from "DRONEPOOL.h"顺便说一句,这是来自“DRONEPOOL.h”

my code:我的代码:

//#include <winsock2.h>
//#include <ws2tcpip.h>
#include <Windows.h>
#include "BUFFER.h"

#ifndef __DRONEPOOL_H__
#define __DRONEPOOL_H__

#define DRONE_POOL_SIZE 100

#define DRONESTATE_EMPTY   0
#define DRONESTATE_IDLE    1
#define DRONESTATE_WORKING 2
#define DRONESTATE_PICKUP  3   // work result ready for pickup

#define LPCLIENTCONNECTION CLIENTCONNECTION*
struct CLIENTCONNECTION
{
//  SOCKET skSocket;
    WORD   wState;
};


#define LPDRONEPOOL DRONEPOOL*
class DRONEPOOL
{
pritave:
    BUFFER bfTaskBuffer;
    BUFFER bfResultBuffer;
    CLIENTCONNECTION ccPool[DRONE_POOL_SIZE];
    UINT iPoolHead;
    UINT iPoolTail;
    HANDLE hPoolMutex;
    HANDLE hManagerThread;
    static DWORD WINAPI Manager(__in LPVOID);
public:
    DRONEPOOL();
    ~DRONEPOOL();
    BOOL InsertDrone(SOCKET);
    BOOL AssignTask(LPXMSG);
    BOOL PeekResult(LPXMSG);
    BOOL GetResult(LPXMSG);
};

#endif

The error is: ERROR C2275: 'BUFFER': Illegal use of this type as expression错误是:ERROR C2275: 'BUFFER': Illegal use this type as expression

Any idea how to resolve this problem?知道如何解决这个问题吗?

Most likely the misspelled private is confusing the compiler on the next line where your BUFFER bfTaskBuffer is declared.最有可能拼写错误的private在声明BUFFER bfTaskBuffer的下一行使编译器感到困惑。

EDIT: Also a few comments about the code and style:编辑:还有一些关于代码和样式的评论:

  • Double underscores are reserved in any context, and leading underscores are some contexts (followed by capital letter or in the global namespace, maybe others).双下划线在任何上下文中都保留,前导下划线是某些上下文(后跟大写字母或在全局命名空间中,可能还有其他)。 Just use DRONEPOOL_H .只需使用DRONEPOOL_H
  • Typically all caps is reserved for constants.通常,所有大写字母都保留给常量。 Consider Dronepool instead of DRONEPOOL .考虑Dronepool而不是DRONEPOOL
  • Instead of using #define for the pointer alias, use typedef: After the class definition do typedef DRONEPOOL* LPDRONEPOOL;不要使用#define作为指针别名,而是使用 typedef:class 定义之后执行typedef DRONEPOOL* LPDRONEPOOL; which creates a type alias, not text substitution.它创建了一个类型别名,而不是文本替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM