?
Solved

Exporting static template members from a DLL

Posted on 1998-01-15
2
Medium Priority
?
251 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

770 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