Solved

Exporting static template members from a DLL

Posted on 1998-01-15
2
247 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 300 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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