当我尝试访问线程之外的向量时,出现链接错误。我的设计是,当我从客户端收到消息时,我想让按摩或数据进入我的数据队列以便进一步操作。但我无法让他们工作。这里是我的代码:问题:访问线程内的向量
.cpp文件:
// Inside the recv thread
start:
err = recvfrom(RecvSocket, lpData->RecvBuf, BufLen, 0, (SOCKADDR *)&lpData->SenderAddr, &SenderAddrSize);
//lpData is used to access Recv Structure which stores the attributes of the server and client.
switch(lpData->port)
{
case 6516:
{
BuffStack1.push_back(lpData->RecvBuf);
break;
}
case 6517:
{
break;
}
case 6518:
{
break;
}
}
goto start;
.h文件中:
class CUdpSocket
{
public:
CUdpSocket(void);
~CUdpSocket(void);
void ServerRecv(int port);
void ClientSend(const char *ip, int port, const char *buff);
unsigned static __stdcall ServerRecvThread(void *arguments);
unsigned static __stdcall ClientSendThread(void *arguments);
CString static Itoa(int data);
void Mix();
private:
RecvStruct *pRecvData;
SendStruct *pSendData;
vector<HANDLE>threadStl;
static vector<char*>BuffStack1; // Here is my stack vector
static vector<char*>BuffStack2;
static vector<char*>BuffStack3;
HANDLE hThread;
unsigned threadID;
static BufferData *ptrBufferData;
};
我有点困惑我是否需要把静态。而当我把静态的,错误是:
error LNK2001: unresolved external symbol "private: static class std::vector<char *,class std::allocator<char *> > CUdpSocket::BuffStack1" ([email protected]@@[email protected][email protected]@[email protected]@@[email protected]@A)
如果我没有把静态的说法,错误说:
error C2228: left of '.push_back' must have class/struct/union
请帮助。
谢谢。
我不能让它们工作。你能告诉我怎么样? – 2011-03-20 11:39:51
你能更具体吗?你遇到了什么错误?什么特别是不工作? – templatetypedef 2011-03-20 18:15:48
没关系。我已经弄明白了。感谢您的帮助。 – 2011-03-22 04:54:24