I have a class which overrides the default empty constructor to provide a constructor with a single parameter. If I use the mfc IMPLEMENT_DYNAMIC macro with this class, I get the error: no appropriate default constructor available. It's simple to solve by adding an empty constructor, but I wondered why this is needed. I am forced to make this protected and add an assert(false) to it to ensure nobody uses it.
A:
C++ provides a default no-argument constructor only if you don't declare your own constructor. I think DECLARE_DYNAMIC requires a no-argument constructor.
Robert Karl
2009-09-18 07:42:57
Perhaps my question wasn't put so well. I understand that DECLARE_DYNAMIC requires a no argument constructor, I am asking why that is the case.
rioch
2009-09-18 20:40:36
+2
A:
The following compiles and runs under Visual Studio 2008. What version of Visual Studio do you use? Can you try compiling this snippet and posting the error message? Could you look into afx.h
and post the definition of DECLARE_DYNAMIC
and IMPLEMENT_DYNAMIC
(and other relevant macros like IMPLEMENT_RUNTIMECLASS
)?
#include <afx.h>
struct CAge : CObject
{
CAge(int n) {}
DECLARE_DYNAMIC(CAge)
};
IMPLEMENT_DYNAMIC(CAge, CObject)
int main()
{
CAge a(10);
}
avakar
2009-09-18 07:48:57