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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:42:43+00:00 2026-05-16T03:42:43+00:00

How should the following cases be handled: I have some geometrical storage, which is

  • 0

How should the following cases be handled:

I have some geometrical storage, which is a template from vertex type.

template <typename T> struct Geometry {

std::vector<T>& GetVertices() { ... }

const void* RawVertices() const { ... }

}

This works fine, unless I want to store different types of geometries (for instance, Geometry<Vertex1> g1 and Geometry<Vertex2> g2 in one container.

Is this possible?

Or how should I implement geometry storage (where I can store and retrieve different types of geometries using one container) or maybe somehow map T type to Geometry<T> type?

Any advices?

Thank you.

  • 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-16T03:42:44+00:00Added an answer on May 16, 2026 at 3:42 am

    Since a container is tied to one type of data it can contain, you could create a class GeometryBase from which all Geometry<T> are derived and then store GeometryBase pointers in your container.

    struct GeometryBase
    {
        // Non-template methods might go here.
        // Don't forget to declare the base class destructor virtual.
    };
    
    template <typename T> struct Geometry : public GeometryBase
    {
        // Template methods go here
    };
    

    Edit:
    At some point you will have to decide which type of vertex container you want to get (my approach) or what you want to do with a vertex (Vijay Mathew’s approach) and then you’ll have to dynamic_cast<> in order to get access to the derived class methods.

    Another suggestion:
    If the types are as different as your describe in your comments, it might actually be better to treat them as different types.
    For example, you could create a separate container for each Geometry<> template instance.

    class SomeStorageClass
    {
    /* ... */
    private:
        std::vector< Geometry<Vertex1> > m_vertex1Geometries;
        std::vector< Geometry<Vertex2> > m_vertex2Geometries;
    };
    

    If you have functions that operate on one kind of geometry (using Vertex1::GetPos(), to use your example) or the other (Vertex2::GetUV()) then these functions are probably implemented quite differently and thus deserve to be separate functions expecting diferent types of parameters.

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

Sidebar

Related Questions

I have the following situation and I'm expecting some expert advise from SO folks.
I have a NUL delimited output coming from the following command : some commands
I have the following expression that should match the entire given word in case
The following should find me the elector ID and the date. For some reason
The following code should display the id out of the JSON-object, which I got
I'm often confronted with the following situation: I have some data in a table
I have an Android application that generates some HTML which is rendered locally, in
i have the following problem. The 1st step is to implement a program, which
I have the following form which intercepts the ENTER key so that when the
Can anyone tell me what the result to the following should be according to

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.