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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:26:18+00:00 2026-05-15T15:26:18+00:00

I noticed that I’m often in the need of a container class. For example

  • 0

I noticed that I’m often in the need of a container class. For example when working on a particle system, I create a container class Particles which has a member vector<Particle*>. Then I call: Particles* my_particles like my_particles->draw(), and in the Particles.draw() I iterator over the vector<Particle*> and call draw() on each of the particles again. The same works for member functions like update(), addforce() etc.. Now, I’m working on a project and need a collection of Cube on which I need to call tween(), moveTowards() etc..

I know I can use template, but in the case of a template class the member functions need to be knows before. As I want to check if I can make a generic class, that I can use for example both my Cubes and Particles collections.

Someone who has done this before or can give me some advice on this?

Kind regards,
Pollux

  • 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-15T15:26:19+00:00Added an answer on May 15, 2026 at 3:26 pm

    The short answer is that you can’t do this in c++. You can, however, use STL algorithms and containers to wrap this behavior up.

    First, you’d put your Cube or Particle instances into a std::vector or other container (like you have now).

    Then you’d use STL’s std::for_each in combination with std::mem_fun.

    It’d result in something like this:

      std::vector<Particle*> V;
    
      V.push_back(new Particle);
      V.push_back(new Particle);
      V.push_back(new Particle);
      V.push_back(new Particle);
    
      std::for_each(V.begin(), V.end(), std::mem_fun(&Particle::draw));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that in Java, you can use a class which has members of
I noticed that static assertions in class templates are not triggered when instantiations are
I noticed that I have views that need the same information like others. But
I noticed that my Designer.vb file of one of my forms has a lot
I noticed that the castle windsor fluent component registration interface has the rather confusing
I noticed that a standard :hover on images, which are displayed with an unoriginal
I noticed that DateChooser has the method setFirstDayOfWeek(int) , but since DateChooser does not
I noticed that a raw type of a generic class can take(point to) all
I noticed that some elements have attributes which are boolean. I wonder why the
I noticed that I can extend a class and at the same time pass

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.