user722132
user722132

Reputation: 119

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. 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). 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.

Btw, this is from "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

Any idea how to resolve this problem?

Upvotes: 2

Views: 5753

Answers (1)

Mark B
Mark B

Reputation: 96233

Most likely the misspelled private is confusing the compiler on the next line where your BUFFER bfTaskBuffer is declared.

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.
  • Typically all caps is reserved for constants. Consider Dronepool instead of DRONEPOOL.
  • Instead of using #define for the pointer alias, use typedef: After the class definition do typedef DRONEPOOL* LPDRONEPOOL; which creates a type alias, not text substitution.

Upvotes: 5

Related Questions