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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:05:36+00:00 2026-05-27T07:05:36+00:00

Templates may not be the answer here but I tried some inheritance and that

  • 0

Templates may not be the answer here but I tried some inheritance and that didn’t work so here is where I am at.

The Problem:

I have an abstract base class that houses all my “work” functions. I’ll then have a bunch of other classes that extend that base class and essentially just fill in the details of the data to pass down into the “work” functions as well as overriding a couple of the base classes functions.

One of the main pieces of data that will change in each derived class is a struct.

So my initial plan of attack was to have a BaseStruct defined and the abstract base class just did all of it’s work on that base struct. If the derived classes used a different struct that extended that base struct then that’s fine.

The problem I ran into with this is that I couldn’t get the size of the struct since in the work function the type of the struct it was operating on is a BaseStruct rather than the derived type.

So now I’m looking at templates.

Essentially I want to have a Base function that does this:

template<typename StructType>
void AbstractMaterial::CreateVertexBuffer() {

    StructType* array = new StructType[numVertices];

    size_t si = sizeof(StructType) * numVertices;

    ...
}

Of course without actually passing anything into this function, it doesn’t really work. I’d rather not create an instance of StructType to pass in just to get the type information but it doesn’t seem like there is any other way?

Essentially I want derived classes to someone specify a StructType to use when this function is called.

Thanks!

  • 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-27T07:05:37+00:00Added an answer on May 27, 2026 at 7:05 am

    This invocation should work:

    For class (static) function:

    AbstractMaterial::CreateVertexBuffer<MySpecificStruct>();
    

    For member function:

    instance.CreateVertexBuffer<MySpecificStruct>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some smart pointer templates, such as boost::shared_ptr, may be instantiated with void to hold
I am using string template to render some content, but the content may be
C++ templates have been a blessing in my everyday work because of its power.
This may not be relevant but just wanted to ask, IF an object is
I am creating a web page that includes several HTML-templates that may contain IDs.
I have a class ( Voxel ) with subclasses which may or may not
I have some random HTML layouts that contain important text I would like to
My site uses jQuery 1.4.2. The problem is .replaceWith() does not work in IE6
I've already read this but it doesn't answer to my question. Here's my scenario:
I have been trying to write a recursive function that searches a stack, but

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.