简体   繁体   中英

Class constructor defining inherited classes constructor syntax error in header file

I have the below code giving me a syntax error on the BindingSocket definition, my understanding was if I wanted to define an inherited classes constructor I continue the BindingSocket definition with BindingSocket(...):Socket(...); , however this gives me a standard syntax error output.

#ifndef NETWORKING_BINDINGSOCKET_HPP_
#define NETWORKING_BINDINGSOCKET_HPP_

#include <stdio.h>
#include "Socket.hpp"

namespace HDE
{
    class BindingSocket: public Socket
    {
        public:
            BindingSocket(...) : Socket(...);
    };
}

and then within my main cpp file I can write:

HDE::BindingSocket::BindingSocket(...): Socket(...)
{

Strangely enough if I add a {} at the end of the header definition for the class I get no syntax error.

The inheritance is given by class BindingSocket: public Socket .

The : Socket(...) after the constructor calls the parent constructor and belongs to the definition and not to the declaration.

So it has to be:

namespace HDE
{
    class BindingSocket: public Socket
    {
        public:
            BindingSocket(...);
    };
}

And:

HDE::BindingSocket::BindingSocket(...): Socket(...)
{

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM