Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:35:42+00:00 2026-06-15T14:35:42+00:00

I am writing a serialize and deserialize method, and I encountered a problem in

  • 0

I am writing a serialize and deserialize method, and I encountered a problem in the implementation of deserialize: I can’t new a value_type, which is actually a Skill*.

template <class T >
static istream &DeSerializePVector(istream& istream_, T& container)
{
  typedef typename T::value_type ElementType;
  size_t size;
  istream_ >> size;
  container.reserve(size);
  container.resize(size);

  for(typename T::iterator ite = container.begin(); ite != container.end(); ite++)
  {
     *ite = new *ElementType;   //how can  I initialize this type?
     (*ite)->DeSerialize(istream_);
  }

  return istream_;
}

int main()
{
    Skill*  disease = Factory::CreateSkill ( SKILLTYPE_DISEASE );
    Skill*  purify = Factory::CreateSkill ( SKILLTYPE_PURIFY );
    Skill* skills[2] = {disease, purify};
    vector<Skill*> int_vector = Tools::MakeVector ( skills );
    ofstream fileOut;
    fileOut.open ( "data.txt", std::ofstream::binary );

    ISerializable::SerializePVector( fileOut, int_vector );
    fileOut.flush();
    fileOut.close();

    ifstream fileIn;
    vector<Skill*> int_vector2;
    fileIn.open ( "data.txt", std::ofstream::binary );
    ISerializable::DeSerializePVector( fileIn, int_vector2 );
}

How am I supposed to get this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:35:42+00:00Added an answer on June 15, 2026 at 2:35 pm

    Assuming ElementType has a default constructor, then

    *ite = new ElementType;
    

    It ElementType is already a pointer type, then you may need this (C++11):

    #include <type_traits>
    
    *ite = new typename std::remove_pointer<ElementType>::type;
    

    If you don’t have C++11 support, you can use the boost equivalent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a C#.NET program which uses XmlSerializer to serialize and deserialize the project
I'm writing classes which (de)serialize to/from XML. When serializing and deserializing, the class gets
I'm writing a windows service application that needs to serialize and deserialize XML documents
I am writing a class library which abstracts data contained in XML files on
Is there an option (except writing custom serializer/deserializer) in GSON library to NOT serialize/deserialize
I'm currently writing a serialization module in Python that can serialize user defined classes.
I'm not getting how can serialize help me in writing efficient PHP application .
Below is the part of a class, I am currently writing, which should take
I'm writing some unit tests that serialize and deserialize all of our types that
I am writing functions that serialize/deserialize a large data structure for efficient reloading later

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.