Solved

enum value and serialization

Posted on 2004-10-12
4
792 Views
Last Modified: 2013-11-20
I get the following compiler error:  Why, how can I fix this problem, and what is the best way to handle enum's in serialization?  

data.cpp(66) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'enum CMyData::MyrEnum' (or there is no acceptable conversion)
Error executing cl.exe.

Given the code snippet:

class CMyData : public CCmdTarget
{
DECLARE_DYNCREATE(CMyData )

CMyData ();           // protected constructor used by dynamic creation

public:
static enum GenderEnum { enumOne = 0,   enumTwo } ;

private:
MyEnum m_eMyEnum ;

// Operations
public:
 virtual void Serialize(CArchive& ar);
}

void CMyData::Serialize(CArchive& ar)
{
 CObject::Serialize(ar);

if (ar.IsStoring()) {
ar << m_eMyEnum ;
}
else {
ar>> m_eMyEnum ;
}


 
0
Comment
Question by:Surfer
4 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 500 total points
ID: 12293922
Do like this. (Althrough << does not complain, you still have to cast its type for safety)
      if (ar.IsStoring())
      {
            ar << (LONG)m_eMyEnum ;
      }
      else
      {
            ar>> (LONG&)m_eMyEnum ;
      }
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12295109
have a look at the "code" at the following  link

http://www.codeguru.com/Cpp/data/data-misc/xml/article.php/c4567/
0
 

Author Comment

by:Surfer
ID: 12560465
Thanks for reminding me to give the well deserved points!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 69
either24  challenge 19 90
has77  challenge 9 73
Message not shown 5 33
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now