Solved

enum value and serialization

Posted on 2004-10-12
4
811 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 71
move a line in eclipse 3 109
tripleUp challenge 7 93
zeroFront challenge 7 124
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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