www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Fct ptr to exported member fct

↑ ↓ ← "dt" <tinkham ucalgary.ca> writes:
DMC Compiler version 8.42n
Win2K
IDDE
-WD

I have a class that I am exporting during compilation for building a dll.

I am getting the "cannot find constructor" error during compilation, in
AbstractContainer::init(). Here is the error exracted from source listing
file:

void AbstractContainer::init()
{

 controlHandler_ = new ControlEvHandler<AbstractContainer>( this,
                                  &AbstractContainer::containerResized);
                                                                       ^
AbstractContainer.cpp(26) : Error: cannot find constructor for class
matching ControlEvHandler<AbstractContainer
::ControlEvHandler<AbstractContainer >(AbstractContainer*,void (

&AbstractContainer::containerResized); } I believe the problem is with "AbstractContainer::*__export member func" in output error above, which is expecting a pointer to an exported member function. If I do not export the member function, the error disappears. Here is some of the code that hopefully can illustrate the problem. //================ from EventHandler.h ============================ class __declspec(dllimport) EventHandler { //yes, importing this one public: EventHandler(){} ~EventHandler(){} // code removed }; // Note the fct. pointer typedef below. This will be the fct. pointer to AbstractContainer::containerResized template <class SOURCE, class EVENT> class EvHandInst : public EventHandler { public: typedef void(SOURCE::*OnEvHandMethod)( EVENT* e ); EvHandInst( SOURCE* source, OnEvHandMethod handlerMethod) { source_ = source; handlerMethod_ = handlerMethod; } virtual ~EvHandInst(){ } protected: SOURCE* source_; OnEvHandMethod handlerMethod_; }; //============= from AbstractContainer.h =================== class __declspec(dllexport) ControlEvent { public: ControlEvent( ); ~ControlEvent(); //code removed }; template <class SOURCE_TYPE> class ControlEvHandler : public EvHandInst<SOURCE_TYPE, ControlEvent> { public: ControlEvHandler( SOURCE_TYPE* source, EvHandInst<SOURCE_TYPE, ControlEvent>::OnEvHandMethod handlerMethod) : EvHandInst<SOURCE_TYPE, ControlEvent>( source, handlerMethod) { } }; class __declspec(dllexport) AbstractContainer : public Container { public: AbstractContainer(); virtual ~AbstractContainer(); void init(); protected: EventHandler* controlHandler_; void containerResized( ControlEvent* event ); private: int dumb_; }; member init() creates an ControlEvHandler (has base class EventHandler), and note I am passing the address of (exported) member AbstractContainer::containerResized. The error occurs in this fct., because it can't find a constructor taking an exported member fct. address? void AbstractContainer::init() { controlHandler_ = new ControlEvHandler<AbstractContainer>( this, &AbstractContainer::containerResized); } I am thinking the problem is the syntax of the typedef of fct. pointer in class EvHandInst: typedef void(SOURCE::*OnEvHandMethod)( EVENT* e ); but I am not sure of this. Is there a special way to note a fct. pointer is to an exported member fct? Or, am I doing something else wrong here? I ask here, because I don't get this error with some other compilers, and am thinking I just need slightly different (correct) syntax for DMC compiler. Thanks for any help.
May 09 2005
↑ ↓ → "dt" <tinkham ucalgary.ca> writes:
"dt" <tinkham ucalgary.ca> wrote in message
news:d5pfrr$dov$1 digitaldaemon.com...
 I am thinking the problem is the syntax of the typedef of fct. pointer in
 class EvHandInst:

 typedef void(SOURCE::*OnEvHandMethod)( EVENT* e );


 but I am not sure of this.

 Is there a special way to note a fct. pointer is to an exported member fct?
 Or, am I doing something else wrong here?  I ask here, because I don't get
 this error with some other compilers, and am thinking I just need slightly
 different (correct) syntax for DMC compiler.

 Thanks for any help.

Well, I guess DMC wants exactly what it is asking for. If I change typedef void(SOURCE::*OnEvHandMethod)( EVENT* e ); to typedef void(SOURCE::*__export OnEvHandMethod)( EVENT* e ); Then this particular error message is removed. However, we have classes (with member funcs) that are not exported, and when they use the above code with __export added, we get the corresponding error message for the case where the 'constructor' without __export cannot be found. It seems odd that all the VC, borland, CW, and MinGW gcc3.3.1 can handle all this transparently. Is this a compiler bug, or no? Doug
May 27 2005