2014-03-30 3 views
0

다른 유형의 소켓 (클라이언트 및 서버)을 만들기위한 정적 멤버가있는 소켓 클래스를 만듭니다.cpp 소켓, 상속 오류

class Socket{ 
    public: 
     int sendData(std::string _data); 
     std::string receiveData(); 

     int closeSocket(); 

    protected:  
     Socket(); 
     virtual int initializeSocket() = 0; 
     virtual int connectSocket() = 0; 


    public:  // static members: Factory, etc. 
     static Socket* createClientSocket(std::string _ip, std::string _port); 
     static Socket* createServerSocket(std::string _port); 

    protected: 
     WSADATA mWsaData; 
     SOCKET mSocket; 

     addrinfo *mResult, mHints; 

아이들은 다음과 같습니다 : 여기에 인터페이스입니다

-> 서버 :

class ServerSocket: public Socket{ 
    private: 
     ServerSocket(const std::string _port); 
     ~ServerSocket(); 

     int acceptClient(); 

    private: 
     SOCKET mClientSocket; 

     std::string mPort; 
    }; // class ServerSocket 

-> 클라이언트 :

class ClientSocket: public Socket{ 
    private: 
     ClientSocket(const std::string _ip, const std::string _port); 
     ~ClientSocket(); 

    private: 
     addrinfo *mPtr; 

     std::string mServerIp, mServerPort; 
    }; // class ClientSocket 

그러나 initializeSocket 등을 구현하면서 멤버들에게 "상속 된 멤버는 허용되지 않습니다."라는 에러 메시지가 나타납니다. 아버지 계급의 보호받는 피라미드. 왜이 오류가 발생합니까? 사전 :)에서

감사

편집 : 오류가 내가 쓴 ServerSocket.cpp

int ServerSocket::initializeSocket(){ <<--- HERE in the name of the function appears 
    // Resolve the server address and port 
    int iResult = getaddrinfo(NULL, mPort.c_str(), &mHints, &mResult); 
    if (iResult != 0) { 
     printf("getaddrinfo failed with error: %d\n", iResult); 
     WSACleanup(); 
     return 1; 
    } 

    //..... ETC.... 

    freeaddrinfo(mResult); 

    iResult = listen(mSocket, SOMAXCONN); 
    if (iResult == SOCKET_ERROR) { 
     printf("listen failed with error: %d\n", WSAGetLastError()); 
     closesocket(mSocket); 
     WSACleanup(); 
     return 1; 
    } 
    return 0; 
    } 

예를 들면, 많은 회원에서 발생 "< < - 여기를 ..."

1>..\..\source\core\comm\ServerSocket.cpp(37): error C2509: 'initializeSocket' : member function not declared in 'BOViL::comm::ServerSocket' 
1>   c:\programming\bovil\source\core\comm\ServerSocket.h(18) : see declaration of 'BOViL::comm::ServerSocket' 
+0

*이 * 당신은 오류를 어디서받을 수 있나요? 정확한 오류는 무엇입니까? 질문을 편집하여 전체 및 수정되지 않은 오류 로그를 포함하고 오류의 출처를 알려주십시오. –

+0

[상속 된 멤버가 허용되지 않는 이유는 무엇입니까?] (http://stackoverflow.com/questions/15117591/why-is-inherited-member-not-allowed) –

+0

그 기사를 읽은 Steve Howard,하지만 저는 찾을 수 없습니다. 문제 :/ – Bardo91

답변

0

오류는 파생 클래스가 선언에서 멤버 함수를 선언하지 못했습니다.

class ClientSocket: public Socket{ 
    public: 
     int sendData(std::string _data); <<--- Add this 

    private: 
     ClientSocket(const std::string _ip, const std::string _port); 
     ~ClientSocket(); 

     int initializeSocket(); <<--- Add this 
     int connectSocket(); <<--- Add this 

    private: 
     addrinfo *mPtr; 

     std::string mServerIp, mServerPort; 
    }; // class ClientSocket 

등 다른 클래스의