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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:32:42+00:00 2026-05-31T21:32:42+00:00

I have a question about the use of multidimensional std::intializer_list in C++. I have

  • 0

I have a question about the use of multidimensional std::intializer_list in C++. I have a Matrix class, and I want to be able to initialize it like this:

Matrix<int, 3, 3> m({{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});

The constructor that I have now takes an argument of a two-dimensional initializer list, but the compiler doesn’t like how I’m using it. Here’s the code:

template<typename T, unsigned int rows, unsigned int cols>
Matrix<T, rows, cols>::Matrix(std::initializer_list<std::initializer_list<T> > set)
{
    std::vector<std::initializer_list<T> > setVec = set;
    std::vector<std::vector<T> > v;

    for (std::vector<std::initializer_list<T> >::iterator i = setVec.begin(); i != setVec.end(); i++)
    {
        v.push_back(std::vector<T>(*i));
    }

    this->matrixData = new T*[rows];

    for (unsigned int i = 0; i < rows; i++)
    {
        this->matrixData[i] = new T[cols];

        for (unsigned int j = 0; j < cols; j++)
        {
            this->matrixData[i][j] = v[i][j];
        }
    }
}

And here’s the error:

..\/utils/Matrix.h:138:7: error: need 'typename' before 'std::vector<std::initializer_list<_CharT> >::iterator' because 'std::vector<std::initializer_list<_CharT> >' is a dependent scope

How do I get rid of that error? Is there a way to restructure it so I don’t have to make that ugly vector of an initializer list or something?

  • 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-31T21:32:43+00:00Added an answer on May 31, 2026 at 9:32 pm

    Yes, as the error message says, you need to write typename here:

    typename std::vector<std::initializer_list<T>>::iterator i = setVec.begin();
    

    It is because iterator is a dependent name. Read this for detail explanation:

    • Where and why do I have to put the "template" and "typename" keywords?

    If your compiler supports auto introduced by C++11, then you could write this:

    auto i = setVec.begin();
    

    which is much better syntax. Since you’re already using C++11 feature such as std::initializer_list, you should start using auto wherever it makes your life easy.

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

Sidebar

Related Questions

I have a question about combobox.I use visual c# and I want to insert
Today I have question about Eclipse . I use this IDE very long and
I have a question about the REST and Apache wink. I want to use
I have a question about a MySQL query. I would (obviously) like to use
I have a question about the use of data structures such as ArrayLists in
I have a question about making static libraries that use other static libraries. I
Recently I have asked a question about what I should use to create self-contained
I have question about parsing in Html helper : I have sth like: @foreach
I'm new to OOD so I have a question about the use of classes
i have question about why should we use return in get,if dont use what

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.