Solved

Exporting static template members from a DLL

Posted on 1998-01-15
2
216 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
2 Comments
 
LVL 2

Accepted Solution

by:
anichini earned 300 total points
Comment Utility
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
Comment Utility
Thanks!!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now