VC ++未声明的标识符

时间:2016-01-19 01:12:13

标签: c++ visual-studio

为什么在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项目,用于客户端应用程序。在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

2 个答案:

答案 0 :(得分:1)

您之前的包含"可能会出现语法错误或遗漏"SocketToSocketContainer.h"或遗失#include

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

编辑:它可能在列表中更进一步 - 任何包含中的任何开放或不正确的#IFDEF都可以删除整个

答案 1 :(得分:0)

我发现了自己的错误。 GClientLib_H已经定义。

#ifndef GClientLib_H
#define GClientLib_H

已更改为

#ifndef TunnelContainer_H
#define TunnelContainer_H

现在一切正常。感谢您的快速回复