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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:51:18+00:00 2026-06-04T16:51:18+00:00

dI am programming a simulation. Now it should both work with 2D and 3D,

  • 0

dI am programming a simulation. Now it should both work with 2D and 3D, so I’m trying to make my classes work with 2D- and 3D-Vectors. Also the Vectors should have an template parameter to indicate which type should be used for the coordinates.

My base class looks like this:

class SimulationObject {
    AbstractVector<int>* position;
    AbstractVector<float>* direction;
}

Now the problem is, I can’t use polymorphism, since then all my Vectors would have to be pointers and this makes operator-overloading nearly impossible for operations like this:

AbstractVector<float>* difference = A.position - (B.position + B.direction) + A.direction;

But also I can’t use a template parameter to specify which type to use:

template <typename T> class Vector2d;
template <typename T> class Vector3d;

template <class VectorType> class SimulationObject {
    VectorType<int> position;
    VectorType<float> direction;
}


SimulationObject<Vector2D> bla; 
//fails, expects SimulationObject< Vector2D<int> > for example.
//But I don't want to allow to specify
//the numbertype from outside of the SimulationObject class

So, what do?

  • 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-04T16:51:19+00:00Added an answer on June 4, 2026 at 4:51 pm

    You can use template template parameters:

    template <template <class> class VectorType> 
    class SimulationObject {
        VectorType<int> position;
        VectorType<float> direction;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm programming an agent-based simulation and have decided that Boost's MultiIndex is probably the
LATER EDIT: Please mention not only game programming books, but also more scientific/simulation oriented
I'm trying to understand how this functional reactive programming works, and I have run
I have been doing web programming for several years now and since then I
I have been programming in Python for a while now, and have created some
I have been trying to wrap my head around functional programming for a while
I have been programming for some months now and a frequently used word is
I'm programming a Monte-Carlo Simulation that should give the user quite some flexibility. Consequently,
I am programming java in Eclipse on Windows XP. I have a multiprocess simulation
I'm just programming a Minecraft Redstone Simulator for Android. I'm doing the simulation with

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.