#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include "testqueueclass.h"
#pragma link "testqueueclass.lib"
const unsigned int MAX_TIMES=50;
int main()
{
TestQueueClass TheTest(0,0);
while(!kbhit())
{
for(int i=0;i<MAX_TIMES;i++)
{
TheTest.PrintCoord();
cout<<"Pushing Idex..."<<endl;
TheTest.PushIndex(rand()%10);
if(i%2==1)
cout<<"value of Index popped is: "<<TheTest.PopIndex()<<endl;
}//for
Sleep(100);
}//while
//this line is causing the trouble
cout<<"TestQueueClass countme is "<<TheTest.countme<<endl;
return 0;
}//main
TestQueueClass.h:
//File: testqueueClass.h - Interface
#ifndef _TESTQUEUECLASS_H
#define _TESTQUEUECLASS_H
#include <iostream.h>
#include <apqueue.h>
#ifndef DLL_API
#define DLL_API __declspec(dllimport)
#endif
class TestQueueClass
{
public:
TestQueueClass(const int x=0,const int y=0);
~TestQueueClass();
void PushIndex(const int i);
int PopIndex();
void PrintCoord();
static unsigned int countme;
private:
apqueue<int> indexQ;
int m_x;
int m_y;
};//TestQueueClass
#endif
TestQueueClass.cpp:
//File: testqueueClass.cpp - Implementation
#ifndef DLL_API
#define DLL_API __declspec(dllexport)
#endif
#include "testqueueclass.h"
DLL_API unsigned int TestQueueClass::countme=0;
DLL_API TestQueueClass::TestQueueClass(const int x,const int y):
m_x(x),m_y(y)
{
countme++;
}//constructor
DLL_API TestQueueClass::~TestQueueClass()
{
countme--;
}//destructor
DLL_API void TestQueueClass::PushIndex(const int i)
{
indexQ.enqueue(i);
}//PushIndex
DLL_API int TestQueueClass::PopIndex()
{
int num=0;
if(!indexQ.isEmpty())
indexQ.dequeue(num);
return num;
}//PopIndex
DLL_API void TestQueueClass::PrintCoord()
{
cout<<"value of x is: "<<m_x
<<"\tvalue of y is: "<<m_y<<endl;
}//PrintCoord
The testqueueclass is the class that''s being compiled as a dll. Funny thing is if I comment out all the lines in my main that accesses the static variables then all is well and it compiles/links fine but if I uncomment it I get that unresolved error:
Error: Unresolved external ''TestQueueClass::countme'' referenced from E:\BORLAND\MYWORKSPACE\TEST.OBJ
Is there something about the way DLL''s are meant to be used that I''m not aware of?
Thanks
--{You fight like a dairy farmer!}