DECLARE_MESSAGE_MAP() Bug - C2248? 
Author Message
 DECLARE_MESSAGE_MAP() Bug - C2248?

I added ~CMapsApp() to CMapsApp() below the DECLARE_MESSAGE_MAP() line and
got the following error:

Maps.cpp(40): error C2248: 'CMapsApp::~CMapsApp' : cannot access protected
member declared in class 'CMapsApp'

If  I move the line above the DECLARE_MESSAGE_MAP() line, it compiles OK.



Mon, 10 Jan 2005 21:18:33 GMT  
 DECLARE_MESSAGE_MAP() Bug - C2248?

Quote:
> I added ~CMapsApp() to CMapsApp() below the DECLARE_MESSAGE_MAP() line and
> got the following error:

> Maps.cpp(40): error C2248: 'CMapsApp::~CMapsApp' : cannot access protected
> member declared in class 'CMapsApp'

> If  I move the line above the DECLARE_MESSAGE_MAP() line, it compiles OK.

As the error message explains, your destructor is protected and you cannot
create instances of classes with a protected destructor unless your are
doing it from a member of that class or a derived class or from a friend. So
a protected section should begin somewhere above the line following
DECLARE_MESSAGE_MAP().

Now take a look at the definition of DECLARE_MESSAGE_MAP and there it is:
private: ... protected: ...

My unimportant advice: Don't put your own declarations among that wizard
generated chaos. Once a wizard has generated code for a class, put a comment
at the beginning of the class definition (Wizard country ahead) and put all
your declarations above the wizard's stuff. To play it safe, add public:
protected: private: just below the comment. That will prevent class wizard
from adding declarations to your declarations:

class YourClass: ...
{
    ... Put your declarations here ...

    // Danger! Wizard Ahead!
public:
protected:
private:
    ... Initial wizard code follows ...

Quote:
};

Regards
    Heinz


Mon, 10 Jan 2005 23:22:51 GMT  
 DECLARE_MESSAGE_MAP() Bug - C2248?
Actually, the wizard is putting the supposed-to-be public functions it adds
below the DECLARE_MESSAGE_MAP() line which is what caused the problem in the
first place.  Obviously the wizards aren't to be trusted.


Quote:


> > I added ~CMapsApp() to CMapsApp() below the DECLARE_MESSAGE_MAP() line
and
> > got the following error:

> > Maps.cpp(40): error C2248: 'CMapsApp::~CMapsApp' : cannot access
protected
> > member declared in class 'CMapsApp'

> > If  I move the line above the DECLARE_MESSAGE_MAP() line, it compiles
OK.

> As the error message explains, your destructor is protected and you cannot
> create instances of classes with a protected destructor unless your are
> doing it from a member of that class or a derived class or from a friend.
So
> a protected section should begin somewhere above the line following
> DECLARE_MESSAGE_MAP().

> Now take a look at the definition of DECLARE_MESSAGE_MAP and there it is:
> private: ... protected: ...

> My unimportant advice: Don't put your own declarations among that wizard
> generated chaos. Once a wizard has generated code for a class, put a
comment
> at the beginning of the class definition (Wizard country ahead) and put
all
> your declarations above the wizard's stuff. To play it safe, add public:
> protected: private: just below the comment. That will prevent class wizard
> from adding declarations to your declarations:

> class YourClass: ...
> {
>     ... Put your declarations here ...

>     // Danger! Wizard Ahead!
> public:
> protected:
> private:
>     ... Initial wizard code follows ...
> };

> Regards
>     Heinz



Tue, 11 Jan 2005 00:09:00 GMT  
 DECLARE_MESSAGE_MAP() Bug - C2248?

Quote:
> Actually, the wizard is putting the supposed-to-be public functions it
adds
> below the DECLARE_MESSAGE_MAP() line which is what caused the problem in
the
> first place.  Obviously the wizards aren't to be trusted.

Most likely, class wizard is only a wizard's apprentic...

My impression with VC6 was that it puts a new member just after the last
public/protected/private, whichever applies, in the class definition. So
actually I separated my class definitions in three instead of only two
parts:

class MyClass
{
    // My (manual made) declarations come first
public:
protected:
private:

    // Initial (app-) wizard stuff
    ...

    // Added by class wizard
public:
protected:
private:

Quote:
};

I don't know, yet, how VC7 wizards behave, but I'll find out.

Regards
    Heinz



Tue, 11 Jan 2005 01:03:23 GMT  
 DECLARE_MESSAGE_MAP() Bug - C2248?
The behavior is probably the same, but guess I just never bumped into this
problem in VC6 in building 1000s of classes.  And with ON_COMMAND_RANGE
statements causing the wizard to report "parent class code read only" its a
little bumpy working with VC7.


Quote:


> > Actually, the wizard is putting the supposed-to-be public functions it
> adds
> > below the DECLARE_MESSAGE_MAP() line which is what caused the problem in
> the
> > first place.  Obviously the wizards aren't to be trusted.

> Most likely, class wizard is only a wizard's apprentic...

> My impression with VC6 was that it puts a new member just after the last
> public/protected/private, whichever applies, in the class definition. So
> actually I separated my class definitions in three instead of only two
> parts:

> class MyClass
> {
>     // My (manual made) declarations come first
> public:
> protected:
> private:

>     // Initial (app-) wizard stuff
>     ...

>     // Added by class wizard
> public:
> protected:
> private:
> };

> I don't know, yet, how VC7 wizards behave, but I'll find out.

> Regards
>     Heinz



Tue, 11 Jan 2005 01:45:52 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Template Bug in 6.0 SP1 (C2248 error)

2. BUG: Template Friend Function Causes Compiler Error C2248 still NOT CORRECTED in VC++6.0

3. BUG: Template Friend Function Causes Compiler Error C2248

4. afx_msg and DECLARE_MESSAGE_MAP

5. afx_msg and DECLARE_MESSAGE_MAP

6. C2248

7. A problem compiling DLLs with protected operator= in VC++ 5.0 (C2248)

8. Why wont this build? C2248 error

9. VC7 ctype error C2248

10. BUG BUG BUG watch variable

11. Bugs Bugs Bugs galore

12. BUG BUG BUG / VIRUS VIRUS VIRUS

 

 
Powered by phpBB® Forum Software