-2
#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?

Fouda
  • 291
  • 1
  • 4
  • 14

1 Answers1

0

The declaration syntax needs to be changed to:

ConnectionType* ConnectionArray = new ConnectionType[NUMBER_OF_CONNECTIONS];
RegularKid
  • 16
  • 1
  • If `NUMBER_OF_CONNECTIONS` is a constant, there is no need to create this dynamically and introduce a possible memory leak. – PaulMcKenzie Nov 21 '14 at 04:02
  • it's not a constant it's #define in another h file not shown hear – Fouda Nov 21 '14 at 04:08
  • Now I get another error error C2039: 'Unref' : is not a member of 'ConnectionType' – Fouda Nov 21 '14 at 04:09
  • I think it's due to using Ptr<> (Smart Pointer) inside my Class, do u have any idea how to fix it – Fouda Nov 21 '14 at 04:11
  • @PaulMcKenzie makes a great point: if you can get away with a static array, then do that so you don't have to worry about releasing that memory when you're done with it. Something like this: ConnectionType connectionArray[NUMBER_OF_CONNECTIONS];. Another small note on convention: variables are usually named with a lower-case first letter and functions are usually named with an upper-case first letter so you can quickly tell them apart. – RegularKid Nov 21 '14 at 04:11
  • @Fouda - A #define *is* constant, unless the #define uses a runtime expression in some form. Show us this `#define` -- if it's as simple as `#define NUMBER_OF_CONNECTIONS 10` or something similar to that, then it is a constant. – PaulMcKenzie Nov 21 '14 at 04:11