Solved

enum value and serialization

Posted on 2004-10-12
4
779 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 58
Doc'in system (example?) BA 7 79
EvenOdd challenge 10 83
matchUp  challenge 9 72
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

10 Experts available now in Live!

Get 1:1 Help Now