0

I have an issue with unresolved external symbol in Visual Studio. I’ve tried all combination of the definition, but i still get the message

1>Exada.obj : error LNK2001: unresolved external symbol "public: static int (__cdecl** Exada::functions_array)(int)" (?functions_array@Exada@@2PAP6AHH@ZA)

The declaration in my header file Exada.h is like this

const int MAX_FUNCTIONS=179;
class Exada
{
public:
static int (*functions_array[MAX_FUNCTIONS + 2])(int);
…
};

And the definition in Exada.cpp file is

int (Exada:: *functions_array[MAX_FUNCTIONS + 2])(int) = { NULL,
&Exada::aporipteos_ar, //1
&Exada::aporipteos_ar, //2
&Exada::aporipteos_ar, //3
… Some address of functions 
}

I appreciate any help. Thanks in advance.

2 Answers2

1

Dealing with arrays of pointers to functions might be troublesome. Use intermediate type alias declarations:

class Exada
{
  // if functions are supposed to be normal or static member functions
  using t_Method = int ( * )(int);
  // if functions are supposed to be non-static member functions
  using t_Method = int ( Exada::* )(int);

  using t_Methods = t_Method[MAX_FUNCTIONS + 2];

  static t_Methods functions_array;
};

// cpp
Exada::t_Methods Exada::functions_array = { nullptr,

Also it would be better to utilize ::std::array wrapper instead of raw array.

user7860670
  • 35,849
  • 4
  • 58
  • 84
0

I’ve tried all combination of the definition

Not all of them. And since you didn't specify what sort of definition you want, this is mostly an educated guess. But if you happen to want a static member array of pointers to non-static member function, the raw syntax would be this:

const int MAX_FUNCTIONS=179;
class Exada
{
public:
    static int (Exada::* functions_array[MAX_FUNCTIONS + 2])(int);
//…
};

And in your implementation file

// One `Exada::` for pointer-to-member and one for scope
int (Exada:: * Exada::functions_array[MAX_FUNCTIONS + 2])(int) = { NULL,
  &Exada::aporipteos_ar, //1
  &Exada::aporipteos_ar, //2
  &Exada::aporipteos_ar, //3
  //… Some address of functions 
}

Which is quite unreadable still. So I'd recommend a type alias to ease both the reading and writing somwhat:

const int MAX_FUNCTIONS=179;
using member_type = int(int);
class Exada
{
public:
    static member_type Exada::*functions_array[MAX_FUNCTIONS + 2];
//…
};
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458