gpt4 book ai didi

c++ - VC++ 未声明的标识符

转载 作者:行者123 更新时间:2023-11-28 05:52:45 48 4
gpt4 key购买 nike

为什么在 Client.cpp 文件中出现错误 C2065:“TunnelContainer”:未定义的标识符?

Client.cpp代码:

#include "stdafx.h"
#include "GClientLib.h"

using namespace GClientLib;

int _tmain(int argc, _TCHAR* argv[])
{
SettingsReader^ settings = gcnew SettingsReader();
SocketToObjectContainer^ STOContainer = gcnew SocketToObjectContainer();
TunnelContainer^ tunnels = gcnew TunnelContainer();

timeval time;
time.tv_sec = 0;
time.tv_usec = 300000;
....

GClientLib.h代码片段:

 #include "Structures.h"
#include "Globals.h"
#include "SettingsReader.h"
#include "SocketToObjectContainer.h"
#include "SocketToSocketContainer.h"
#include "TunnelContainer.h"

已更新。 SocketToSocketContainer.h

#ifndef SocketToSocketContainer_H
#define SocketToSocketContainer_H

#include <cliext/utility>
#include <cliext/list>
#include <cliext/algorithm>

namespace GClientLib {
ref class SocketToSocketContainer {
private:
cliext::list<cliext::pair<int, int>> sarasas;
public:
SocketToSocketContainer(void);
void Add(int, int);
int Find(int);
void Delete(int);
};
};
#endif

GclientLib是lib工程,用于Client应用。在启用 Visual Studio 2013 C++/CLI 的基础上构建

TunnelContainer.h代码:

#ifndef GClientLib_H
#define GClientLib_H

#include <cliext/utility>
#include <cliext/list>
#include <cliext/algorithm>

namespace GClientLib {
enum TunnelStatus
{
JUNGIASI = 1, //Uzmezgamas rysys tarp klientu
LAUKIA_PROGRAMOS = 2, // Laukia kol prisijungs norima kliento porgramine iranga
KOMUNIKACIJA = 3 // Tuneliu vyksta komunikacija
};

ref struct Tunnel
{
int tag; //Tunelio zyme
int dport; //Prievadas, prie kurio jungesi
int clientid; //Kliento ID su kuriuo sujungta
int sport; //Vietinis prievadas
int serverSocket; //Socketas, prie kuris priima duomenu srauta
int status; // Sujungimo statusas (Jungiasi, prisjungta, laukia jungties)
};

ref class TunnelContainer {
private:
// Tuneliu sarasas
cliext::list<cliext::pair<int, Tunnel^>> sarasas;
public:
// Konstruktorius
TunnelContainer();
// Pridedamas naujas tunelis. PERRASO statusa i JUNGIAMASI
Tunnel^ Add(Tunnel^ tunelis);
// Pridedamas naujas tunelis. Statusa nustato i JUNGIAMASI
Tunnel^ Add(int tag, int dport, int clientid, int sport, int serverSocket);
// Tunelio paieska pagal tag
Tunnel^ Find(int tag);
// Salina tuneli pagal tag
Tunnel^ Remove(int tag);
// Keicia tunelio statusa
void ChangeStatus(int tag, TunnelStatus status);
};
};
#endif

更新

将 TunnelContainer.h 移动到第一个位置后,在 ToServerSocket.h 文件中出现此错误:

Error   1   error C2143: syntax error : missing ';' before '^' line 16
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int line 16

ToServerSocket.h代码:

#ifndef ToServerSocket_H
#define ToServerSocket_H

#include <iostream>

#include "gNetSocket.h"
#include "ServerSocket.h"
#include "OutboundSocket.h"

namespace GClientLib {
ref class ToServerSocket : public gNetSocket {
private:
char *commandBuffer;
line 16 --->TagGenerator^ tag;
SocketToObjectContainer^ STOC;
SettingsReader^ settings;
public:
ToServerSocket(string ip, string port, fd_set* skaitomiSocket, fd_set* rasomiSocket, fd_set* klaidingiSocket, SocketToObjectContainer^ STOC, SettingsReader^ settings);
virtual int Send(char* data, int lenght) override;
virtual void Recive(SocketToObjectContainer^ container) override;
virtual void Connect() override;
virtual void Reconnect() override;
void CommandList(int page);
void CommandListAck(int rRecv);
void CommandHello();
void CommandHelp();
void CommandInitConnect(int id, int port, SocketToObjectContainer^ container);
void CommandConnect(SocketToObjectContainer^ container);
void CommandClear();
void CommandBeginRead(SocketToObjectContainer^ container);
void CommandClientConnectAck(SocketToObjectContainer^ container);
void CommandInitConnectAck();
void CommandJsonList(int page, SOCKET socket);
void CommandJsonListAck(int rRecv, SocketToObjectContainer^ container);
void CommandJsonInitConnect(int id, int port, SOCKET socket);
void CommandJSONConnect(SocketToObjectContainer^ container);
void CommandJsonInitConnectAck();
int GenerateTag();
};
};

#endif

最佳答案

您可能有语法错误或缺少 ; 或在此之前的包含中缺少关闭 ""SocketToSocketContainer.h"

#include 是一个预编译语句,它所做的只是将给定文件的内容包含到主文件中;您的任务是确保结果是有效代码。因此,如果一个 include 的语句不完整,则第二个 include 的内容将继续该语句。

编辑:它可能在列表中更靠前 - 任何包含中的任何打开或不正确的#IFDEF 都可能删除整个其余部分

关于c++ - VC++ 未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866929/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com