i have the following code in a DLL, in a header file called TemplateT:
#pragma once
template<class T>
class __declspec(dllexport) TemplateT {
public:
static int number;
TemplateT(int num) {
number = num;
}
int getNumber() {
return number;
}
};
template<class T>
int TemplateT<T>::number;
and on another header file called Exported.h
#pragma once
#include "TemplateT.h"
#define EXPORTED __declspec(dllexport)
extern EXPORTED TemplateT<int> exported;
and on Exported.cpp i have:
#include "Exporter.h"
TemplateT<int> exported(5);
As you can see, im initiating the static member "number" to the value of 5. but as i access the variable from another project like this:
#include <iostream>
#include "Exporter.h"
int main()
{
int a = exported.getNumber();
int b = 0;
}
i see the value of number as 0. Ill be happy if you could explain to me this behavior.
EDIT
both are used with visual studio 2019. the dll is compiled with vs19 and the other project with vs10
I found a question about the same situation, but the answers there did not fix it for me