Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exporting static template members from a DLL

Posted on 1998-01-15
2
Medium Priority
?
257 Views
Last Modified: 2013-12-03
I'm trying to create a DLL, and part of my interface includes a class template that contains a static member (simplified version follows):

template<class T>
class Event {
public:
    Event() { ... }

    class Handler {
    public:
       void handle( const T& ) = 0;
       // ...
    };

    static void Register( Handler* pHandler ) {
        ms_registry.push_back( pHandler );
    }

    // ...

private:
    static vector<Handler*> ms_registry;
};

Obviously, the ms_registry member needs to be defined for each instantiation of the template. I have one instantiation defined in the library, something like:

class MyEvent : public Event<MyEvent> {
public:
    // ...
};

This is perfectly legal (though a little weird), and it works great for new subclasses that I create *outside* the DLL (because defining the ms_registry member for subclasses defined outside the DLL is no problem). However, I can't seem to export the definition of the MyEvent::ms_registry field from the DLL (the definition is located in a .cpp file). I have to define it, or the link stage of building the DLL fails, but I can't get clients of the DLL to link with the DLL's definition. HELP!!!
0
Comment
Question by:kfcox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
anichini earned 1200 total points
ID: 1410086
If you are using VC 5.0++, look at the knowledge base article
"HOWTO: Exporting STL Components Inside & Outside of a Class" (ID Q168958)

I think what you need to do is explicitly insantiate the MyEvent class in your CPP file.

0
 

Author Comment

by:kfcox
ID: 1410087
Thanks!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question