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

  • Home
  • SEARCH
  • 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 8262029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:37:23+00:00 2026-06-08T03:37:23+00:00

I’m currently trying to write a function which takes an STL array of any

  • 0

I’m currently trying to write a function which takes an STL array of any type as one of its parameters. The obvious way to write it is:

template<typename T, int count>
void setArrayBufferData(GLenum usage, const std::array<T, count>& data) {
  setArrayBufferData(usage, data.data(), sizeof(T) * count);
}

And here’s the other overload which it calls just for reference

void setArrayBufferData(GLenum usage, void* data, int size) {
  glBufferData(GL_ARRAY_BUFFER, size, data, usage);
}

The function definition compiles fine. However, when I try to call it

std::array<int, 4> data;
setArrayBufferData(GL_STATIC_DRAW, data);

I get a “No matching function for call to ‘setArrayBufferData'” error message. I know if I specified the template parameters in the call it would work, but I want the call to deduce them. I’ve tried researching template template parameters, a more generic declaration followed by an std::array specialization, and every other syntactical variation I could think of, yet I can’t seem to figure out a way to get what I’m looking for. Is it even possible, and if so, what needs to be done?

  • 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-08T03:37:25+00:00Added an answer on June 8, 2026 at 3:37 am
    template<typename T, int count>
    void setArrayBufferData(GLenum usage, const std::array<T, count>& data)
    

    is incorrect, since std::array is template<typename T, size_t N> struct array. The second parameter must be of type size_t, not int.

    Also, data.data() returns const T* since data is const reference to std::array, so, try to setArrayBufferData(GLenum usage, const void* data, int size) or call it with setArrayBufferData(usage, const_cast<T*>(data.data()), sizeof(T) * count);

    #include <array>
    
    void function(const void* ptr, size_t bytes)
    {
    }
    
    template<typename T, size_t count>
    void function(const std::array<T, count>& array)
    {
       function(array.data(), sizeof(T) * count);
    }
    
    int main()
    {
       std::array<int, 4> array;
       function(array);
    }
    

    this example works fine. http://liveworkspace.org/code/2a5af492e1f4229afdd0224171854d1c

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

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

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.