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

  • Home
  • SEARCH
  • 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 6116483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:12:39+00:00 2026-05-23T15:12:39+00:00

I serialize most of my classes with two functions, read() and write(). What I

  • 0

I serialize most of my classes with two functions, read() and write(). What I would like to do is have the read/write() function of the base class called from the subclasses so that I don’t have to repeat the serialization code multiple times.

For example:

class Base
{
public:
   base();
   virtual read(QDataStream&);
   virtual write(QDataStream&);
private:
   int a, b, c, d;
}

class Sub : public Base
{
public:
    Sub();
    read(QDataStream&);
    write(QDataStream&);
private:
    int e, f, g, h;
}

So in this example, i would like the code to read/write a,b,c,d to come from Base. Sub would then call Base::read(QDataStream&) and then add whatever attributes are unique to Sub. This way I don’t have to repeat the serialization code for each subclass (and possibly forget to do so).

  • 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-05-23T15:12:40+00:00Added an answer on May 23, 2026 at 3:12 pm

    You can call base-class functions by prepending the function call with the base-class identifier, followed by the scope operator (::).

    Like this:

    class Base
    {
    public:
         virtual void Function();
    }
    
    class Foo : public Base
    {
    public:
         void Function();
         void DoSomething();
    }
    
    void Foo::DoSomething()
    {
         Base::Function();   // Will call the base class' version of Function().
         Function();         // Will call Foo's version of Function().
    }
    

    EDIT: Note removed by request.

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

Sidebar

Related Questions

I would like to serialize and deserialize objects without having to worry about the
What is the most appropriate way to serialize Java Classes to XML? I tried
The Context I have a custom template container class put together from a map
I've got a rich domain model, where most classes have some behaviour and some
I have a custom class with a serialize method, and I want to be
I'm serializing large quantities of classes, most of them as references (as I have
Quoting from http://sites.google.com/site/gson/gson-design-document : Why are most classes in Gson marked as final? While
I have a rather large class to serialize as Xml, and in order to
Is it possible to serialize and deserialize a class in C++? I've been using
When I serialize; public class SpeedDial { public string Value { get; set; }

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.