dimanche 21 janvier 2018

How does g++ compile pure virtual functions without the "-std=c++11" argument?

I'm creating a thread safe event system to help me manage a UDP server I've created on my raspberrypi 2.

class ThreadEventComponent()
{
public:
  ThreadEventComponent() {}
  virtual ~ThreadEventComponent() {}

  void Start(bool detached = false)
  {
    // start thread

    if(detached)
      // detach thread

    Init();
  }
  virtual void Init() = 0;
};

class NetworkServer
{
public:
  NetworkServer() : ThreadEventComponent() {}
  ~NetworkServer(){}
  void Init()
  {
    // initialize members
  }
};

When I initially tried to compile ThreadEventComponent with g++ -Wall -c "%f" -pthread on the pi, I got the following error.

In member function 'void ThreadEventComponent::Start(bool)':

error: 'Init' was not declared in this scope

But when I changed my compile script to g++ -std=c++11 -Wall -c "%f" -pthread it worked perfectly fine. Does anyone know why g++ is unable to compile this code without the -std=c++11 argument?

Note: I put all this in one file as if it were a .h to make it easier to read. I do have all my function definitions in a separate .cpp file.

Aucun commentaire:

Enregistrer un commentaire