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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:34:25+00:00 2026-06-13T05:34:25+00:00

I am trying to understand a template class in C++. First, I would like

  • 0

I am trying to understand a template class in C++. First, I would like to understand what this line means:

template <typename T, typename Ord = columns, typename All = abc::allocator<T,16> >
class matrix

where columns and allocator are respectively a struct and a class defined somewhere else (the second in the namespace abc). What troubles me is the fact that it seems to have a typename which has already been initialized. What does this mean? Should I also initialize the typename of Ord and All when I want to use this template?

Besides, there is also this only constructor:

explicit matrix(unsigned int rows = 0, unsigned int cols = 0, T init = T())

but it seems to have already been initialized. And what should init mean?

I assure you that I looked at all the code, but there is nothing that helps to understand better. Thank you for your attention.

Edit: Thank you everybody for your answers. Just a little reassurance (I am a noob in C++):

int const& operator() operator()(unsigned int i, unsigned int j) const

This method means that, when we initialize the class foo, we can call it by foo()(1,2), where i=1 and j=2. Am i right? And what do the two “const” refer to?

Thank you again!

  • 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-13T05:34:27+00:00Added an answer on June 13, 2026 at 5:34 am
    template <typename T, typename Ord = columns, typename All = abc::allocator<T,16> >
    class matrix
    { 
        //...
    };
    

    Those are default template parameters, they work just as default function arguments – you can specify them, but if you don’t, they are defaulted.

    And you can see an example of usage of default arguments of the function.


    Bottom line – all the following lines are correct:

    matrix<int> a; // matrix<int, columns, abc::allocator<int, 16> >
    matrix<int, rows> b; // matrix<int, rows, abc::allocator<int, 16> >
    matrix<int, columns, abc::other_allocator<int, 32> > c; // obvious
    
    matrix<int> a = matrix<int>(); // constructor called with 0, 0 and 
    // int() - default constructed T - in this case, int -  as arguments
    matrix<int> a(1, 2); // constructor called with 1, 2 and int() as arguments
    matrix<int> a(1, 2, 100); // obvious
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to understand this code template <typename T, typename _Prd =
Im trying to understand how class generics work and this bit just doesnt make
I've been trying to understand template specializations. Why is this generating an error (
I'm trying to understand where to use template and typename and I came across
I'm trying to understand why this snippet fails: #include <iostream> using namespace std; template
I am trying to understand some C++ syntax: template<class T> class Foo { Foo();
I'm trying to understand how the following class template works (taken from here ),
I am trying to understand STL algorithms. Copy is defined as : template<class InputIterator,
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
Trying to understand Ruby a bit better, I ran into this code surfing the

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.