0

I am trying to call my SocketConnection constructor from inside the definition of the node class, but I'm failing to understand the compile error I'm getting - I fail to see why the compiler thinks the constructor I declared for SocketConnection is not a constructor.

Here are the main parts of .h file code:

class Node
{
    public:
    Node() ; 
    int OnStart() ; 
    friend class SocketConnection ; 
} ; 

class SocketConnection
{
    public:
    Node * m_nptr ; 
    int m_sockfd ; 
    SocketConnection(Node * nptr) ; 
};

Here are the main parts of .cpp file:

int Node::OnStart()
{
    SocketConnection newConnection(this) ; 
    return 0 ; 
}

SocketConnection::SocketConection(Node * nptr): m_nptr(nptr)
{

}

On compilation, I get:

error: ISO C++ forbids declaration of ‘SocketConection’ with no type
error: no ‘int SocketConnection::SocketConection(Node*)’ member function declared in class ‘SocketConnection’
In member function ‘int SocketConnection::SocketConection(Node*)’:
error: only constructors take base initializers

Can someone help me understand this ?

Cheers, N.

4

1 回答 1

1

你有一个错字:

SocketConnection::SocketConection(Node * nptr): m_nptr(nptr)
//                        ^

将其更改为:

SocketConnection::SocketConnection(Node * nptr): m_nptr(nptr)
//                        ^^
于 2013-05-26T10:39:51.750 回答