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
Solved

Exporting static template members from a DLL

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL to ElasticSearch Query 1 702
C# Performance testing with Visual Studio Profession 2015 2 39
PL SQL Developer 7 53
VIDEO DATASOURCE Control Resize issue 2 30
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.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…

861 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