Home > Software engineering >  DLL export static member variables of a class without calls the constructor
DLL export static member variables of a class without calls the constructor

Time:10-04

 
//. H file
# ifdef MYCLASS_EXPORTS
# define DLL_CLASS __declspec (dllexport)
# the else
# define DLL_CLASS __declspec (dllimport)
# endif

The class DLL_CLASS myclass
{
The static vector v;
}

//in the CPP file also defines v
Vector Myclass: : v.


When using v will collapse, and later made test oneself defines A class A, found that the static member variables of A class declaration, can't call the constructor,
Is the structure of the vector function is not called,
And in my test project, before use is invokes the constructor,
Why is this so?
In addition, also tried to define v when export
DLL_CLASS vector Myclass: : v.
Also not line,
General if is not export definition, is the link, however, I this is to be able to compile, link through runtime collapse, the reason is variable constructor execution,

http://stackoverflow.com/questions/21454555/c-constructor-of-static-member-class-not-called
A foreigner and I have the same problem

CodePudding user response:

Why do you want to static?

CodePudding user response:

Not didn't call, but the particularity of the static class members, the client can't normal access to the inside of the DLL static members of the class
Solution:
For the static members do a get set accessor

CodePudding user response:

Look!!!!!!

CodePudding user response:

Is guide c interface, did not dare to use c + +, be afraid of

CodePudding user response:

Export function to C is compatible with, or are pit

Derived class is dig a hole for yourself

CodePudding user response:

Try not static, or add an initialization function, all members to initialize variables

CodePudding user response:

Can you compile?
Your STD: : vector is a template, not __declspec (dllexport),
  • Related