Error while creating C++ array

154 views Asked by At
#include "connection.h"


 ConnectionType[] ConnectionArray = new ConnectionType[NUMBER_OF_CONNECTIONS];

I get 2 errors

  1. Error: expected an identifier
  2. Error: expected a ';'

I have

class ConnectionType {
public:
  Ptr<Socket> txMstrSocPtr; /// Pointer to Master tx socket
  Ptr<Socket> rxMstrSocPtr; /// Pointer to Master rx socket
  Ptr<Socket> txSlavSocPtr; /// Pointer to Slave tx socket
  Ptr<Socket> rxSlavSocPtr; /// Pointer to Slave rx socket

  //ConnectionType();
  //~ConnectionType();

  void rxMstrCallBack(Ptr<Socket> socket);
  void rxSlavCallBack(Ptr<Socket> socket);
};

Defined in connection.h

Do you have any idea why I get these 2 errors?

1

There are 1 answers

6
RegularKid On BEST ANSWER

The declaration syntax needs to be changed to:

ConnectionType* ConnectionArray = new ConnectionType[NUMBER_OF_CONNECTIONS];