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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:51:15+00:00 2026-06-09T22:51:15+00:00

I haven’t done any C++ programming for quite some time and I decided that

  • 0

I haven’t done any C++ programming for quite some time and I decided that I would mess around with it a little bit in my spare time so I decided to write me a little database program just for fun and I’m having trouble with creating an array of templated class objects.

What I have is this class which I want to use to represent a field in a database record.

template <class T, int fieldTypeId>
class Field
{
private:
    T field;
    int field_type;
public:
    // ...
};

And I want to use an array of that class to represent a record in a database using this class.

class Database_Record
{
private:
    int id;
    Field record[];
public:
    Database_Record(int);
    Database_Record(int, Field[]);
   ~Database_Record();
};

Where I’m stuck at is the creation of the array in the Database_Record class since that is an array of templated class objects with each element possibly being of a different type and I’m not sure how I need declare the array because of that. Is what I’m trying to do even possible or am I going about it the wrong way? Any help would be greatly appreciated.

  • 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-09T22:51:17+00:00Added an answer on June 9, 2026 at 10:51 pm

    Field<T1> and Field<T2> are two completely different types. To treat them in a vector you need to generialize then somewhere. You may write AbstractField and

    struct AbstractField{
      virtual ~AbstractField() = 0;
    };
    
    template<class T,int fieldTypeId>
    class Field: public AbstractField{
      private:
        T field;
      public:
        const static int field_type;
      public:
        virtual ~Field(){}
    };
    
    class Database_Record{
      std::vector<AbstractField*> record; 
      public:
        ~Database_Record(){
          //delete all AbstractFields in vector
        }
    };
    

    and then keep a vector of AbstractField. also use vector instead of []. Use AbstractField* instead of AbstractField and write at least one pure virtual in AbstractField.

    you may make the destructor of AbstractField pure virtual. and don’t forget to delete all AbstractFields. in ~Database_Record()

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

Sidebar

Related Questions

I haven't done any C++ in a while, but decided to finish a big
Haven't done ASP.NET development since VS 2003, so I'd like to save some time
I haven't found any documentation on this or seen this done before, but is
Haven't seen this feature anywhere else. I know that the 32nd bit is used
I haven't designed a website for about 3 years now, so I am quite
I haven't done a lot of work with multi-level, pure CSS drop-down menus before,
Haven't been programming in JS for a while. Now, I have following thing: <html>
Haven't seen anything, but I have seen that you can create albums in the
Haven't been coding in a bit, but took on a project for a friend.
I haven't seen easy examples about rotaion around a specified point. I tried something

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.