c++ - compiler error if MFC RUNTIME_CLASS argument has namespace -


i've got answer, see bottom.

note: "_afxdll" not predefined case, linking statically mfc.

i have code this:

myclass.h

namespace mynamespace {     class cmyclass : public cmybase     {         declare_dynamic( cmyclass )         ...     } } 

myclass.cpp

using namespace mynamespace; implement_dynamic( cmyclass , cmybase) 

caller

cmybase* pobject = new mynamespace::cmyclass(); .... pobject->iskindof(runtime_class(mynamespace::cmyclass)) 

when compile, i've got error:

error c3083: 'classmynamespace': symbol left of '::' must type error c2277: 'mynamespace::cmyclass::{ctor}' : cannot take address of member function 

i investigated macro runtime_class , found expanded to:

#define runtime_class(class_name) _runtime_class(class_name) #define _runtime_class(class_name) ((cruntimeclass*)(&class_name::class##class_name))  (cruntimeclass*)(&mynamespace::cmyclass::classmynamespace::cmyclass) 

ideally, if can expand following code, good.

(cruntimeclass*)(&mynamespace::cmyclass::classcmyclass) 

now question:

  1. is known issue microsoft "we can not use namespace in runtime_class"?

  2. a more practical question: reason(e.g. classes different namespace conflict), can not "using namespace" in cpp file, how can use runtime type identification in mfc?

answer hans passant:

microsoft has confirmed bug here.

the workaround quite smart, copied here:

posted bongovr on 8/15/2006 @ 2:39 define yet macro , use instead of runtime_class when namespace-qualified class names used in code: #ifdef _afxdll #define runtime_class_n(n, class_name) (n::class_name::getthisclass()) #else #define runtime_class_n(n, class_name) ((cruntimeclass*)(&n::class_name::class##class_name)) #endif 

this macro works in both builds (_afxdll defined , not defined).

answer hans passant:

microsoft has confirmed bug here.

the workaround quite smart, copied here:

posted bongovr on 8/15/2006 @ 2:39 define yet macro , use instead of runtime_class when namespace-qualified class names used in code: #ifdef _afxdll #define runtime_class_n(n, class_name) (n::class_name::getthisclass()) #else #define runtime_class_n(n, class_name) ((cruntimeclass*)(&n::class_name::class##class_name)) #endif 

this macro works in both builds (_afxdll defined , not defined).


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -