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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:02:21+00:00 2026-06-13T09:02:21+00:00

I want to accomplish the following: Entity e; e.AddComponent<CPosition>(128, 128); //method should instantiate a

  • 0

I want to accomplish the following:

Entity e;
e.AddComponent<CPosition>(128, 128); //method should instantiate a new CPosition(128,128)
e.AddComponent<CSprite>(some, other, args); //etc

The important part is the AddComponent method. It should attempt to construct the generic type with the arguments passed. I believe C++11’s variadic templates to forward the arguments to the constructor. However, I do not have access to this functionality yet (VS2010).

Does anyone have any idea on how to do this?

  • 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-13T09:02:23+00:00Added an answer on June 13, 2026 at 9:02 am

    Write a bunch of overloads, each taking a different number of parameters.

    class Entity
    {
    public:
     template<typename T>
     void AddComponent() { component_ = new T(); }
    
     template<typename T, typename T1>
     void AddComponent(T1 t1) { component_ = new T(t1); }
    
     template<typename T, typename T1, typename T2>
     void AddComponent(T1 t1, T2 t2) { component_ = new T(t1, t2); }
    
     // etc
     ...
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript code using which I want to accomplish the following .
I want to accomplish something like the following (my interest is in the toInt()
Maybe I should first give an idea of what I want to accomplish as
Can some professional experienced Magento developer tell me how to accomplish the following in
I want to accomplish the following: def feed_items a = [] taggings.each do |k|
I want to accomplish something of the following: Select DISTINCT(tableA.column) INTO tableB.column FROM tableA
I'm basically trying to accomplish the following. I want it so 5 seconds after
I want to accomplish the following answer = True myvar = the answer is
With the following code I want accomplish two different values for intA, but I
I want to accomplish the following, but I'm not sure how to do it:

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.