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.

4
  • 1
    Please format your question's code blocks properly. Commented Dec 3, 2017 at 10:12
  • why not using std::function if possible. Your code will be clearer and easier to read and debug. Commented Dec 3, 2017 at 10:13
  • The array declaration in you class is not for pointers to members. So I don't see why you'd expect them to match. Commented Dec 3, 2017 at 10:14
  • i tried static int (Exada::*functions_array[MAX_FUNCTIONS + 2])(int); but still have error Commented Dec 3, 2017 at 10:46

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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];
//…
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.