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 139947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:31:35+00:00 2026-05-11T07:31:35+00:00

I have a data structure that I want to access / modify in different

  • 0

I have a data structure that I want to access / modify in different ways in different situations. I came up with this:

class DataStructure {     public:        int getType();      private:        // underlying data containers     };  class WrapperBase {     public:         void wrap(DataStructure *input)             {dataStructure = input;}      protected:         DataStructure *dataStructure; };  class WrapperOne : public WrapperBase {      public:           // @Mykola: I know bytes 4-10 in an array of type one specify the date           // so this method will format those bytes and return them           Data getDate() };  class WrapperTwo : public WrapperBase {      public:           // @Mykola: There is mostly just a chunk of data in packet type two. So this           // method will turn 4 bytes into an int at position index and return that           int dataAt(int index);               }; 

One problem I see here is that WrapperBase isn’t abstract even though it should be. I could of course add some pure virtual dummy function or an assert(0) in the constructor but that seems too hackish a solution. Or should I get rid of the inheritance entirely since it’s only really done for code-reuse? Any other problems with this solution?

Or am I on the wrong track entirely?

Edit @ Paul

Why do I want to do this? Well, I get several 1000 arrays of serialized data, which I want to add to a dataset. The first few bytes of each array tell me what sort of data it is, which dictates how I have process it. So then I do something like:

// some place in the program dataSet.processData(dataStructure);  // in the data set class DataSet::processData(DataStructure *dataStructure) {      if(dataStructure->getType() == TYPE_ONE)      {           WrapperOne wrapperOne;           wrapperOne.wrap(dataStructure);            processDataTypeOne(wrapperOne);       }       // repeat the above for other data types } 

I could of course put all the logic in the processDataTypeOne function, and that was what I was doing in the beginning, but operating on the raw data structure turned into an ugly mess of index operations. That’s why I’d like to wrap it in an object, which will hide all that.

  • 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. 2026-05-11T07:31:36+00:00Added an answer on May 11, 2026 at 7:31 am

    Make your wrappers to be a data.
    Create factory that will return either data or different wrappers. Here is what I mean.

    class DataStructure { public:     typedef int DataType;      DataStructure( int id ):         id_( id )     {}      DataStructure( const DataStructure& dataStructure );     virtual ~DataStructure();      virtual void Set( const DataType& data ) { data_ = data; }      virtual DataType Get() const { return data_; }      int id() const { return id_; } private:     DataType data_;     int id_; };  class WrapperBase : public DataStructure {  public:     WrapperBase( DataStructure* dataStructure ):         DataStructure( dataStructure->id() ),         dataStructure_( dataStructure )     {}      virtual void Set( const DataType& data );     virtual DataType Get() const; protected:     DataStructure* dataStructure_; };  class WrapperOne : public WrapperBase {  public:     WrapperOne( DataStructure* dataStructure );     virtual void Set( const DataType& data );     virtual DataType Get() const; };  class WrapperTwo : public WrapperBase {  public:     WrapperTwo( DataStructure* dataStructure );     virtual void Set( const DataType& data );     virtual DataType Get() const; };  DataStructure* getWrapper( DataStructure* dataStructure ) {     switch ( dataStructure->id() )     {         case 1: return new WrapperOne( dataStructure );         case 2: return new WrapperTwo( dataStructure );         default: return new DataStructure( *dataStructure );     } }  void processData(DataStructure *dataStructure) {     std::auto_ptr<DataStructure> wrapper( getWrapper( dataStructure ) );     processDataImpl( wrapper.get() ); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer PHP does 'copy on write' anyway, so variables aren't actually… May 11, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer a bit field May 11, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer This can be resolved by using the convention that (...)2… May 11, 2026 at 11:41 pm

Related Questions

Still working on a problem that started from here Calling C++ dll function from
I've got a collection of strings, and I need to know the first index
I have some useful methods for physics calculations like acceleration / deceleration, speed, and
I have a templated function fct that uses some complex data structure based on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.