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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:21:01+00:00 2026-05-26T03:21:01+00:00

I’m reading through a C++ book and I’m in a section about reducing the

  • 0

I’m reading through a C++ book and I’m in a section about reducing the object code generated by templates (Effective C++ III By Scott Meyers). One of the examples it gives is:

template <typename T, std::size_t n>
class SquareMatrix: private SquareMatrixBase<T> {
    public:
        SquareMatrix()
            : SquareMatrixBase<T>(n, 0),
              pData(new T[n*n])
        { this->setDataPtr(pData.get()); }

        ... functions ...

    private:
        boost::scoped_array<T> pData;
};

where the base class, SquareMatrixBase has a function called:

void invert(std::size_t matrixSize);

“The book moves on to say “Regardless of where the data is stored, the
key result from a bloat point of view is that now many — maybe all —
of SquareMatrix’s member functions can be simple inline calls to
non-inline base class versions that are shared with all other matrices
holding the same type of data, regardless of their size.”

What does it mean by “inline calls to non-inline base class versions…”? If its an inline call I would have thought it would have put the whole base class version of any function into the place where inline was used, but this would result in the same code bloat I would have thought. It says this like it’s a benefit against code-bloat though.

If you need more background information let me know, the chapters long though and I tried pretty hard to provide background information but I might have missed something.

||EDIT – Additional Information||

The purpose of having Square Matrix and Square matrix base in this passage was:

SquareMatrix was originally a standalone template (not derived). It contained a series of functions which did operations based on the template parameter n’s value. So, there was essentially a copy of every function for every value of n used (or for every pair of n, T used) as a new template with those functions was instantiated for each parameter pair. SquareMatrixBase was created to move the functions dependent on the size parameter to the base class. Since the base class is only instantiated with a type parameter (and not the size) the functions in the base class can be called by passing in the value for size the derived class passes into the base class constructor. This means there is only one version of the functions for each typename T passed into the SquareMatrix template regardless of the std::size_t n passed in (as opposed to one version of each function for each combination of {T, n}.

  • 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-26T03:21:02+00:00Added an answer on May 26, 2026 at 3:21 am

    The point is that SquareMatrix::invert() is inlined, so the function doesn’t even appear in the resulting code, and instead the protected base function SquareMatrixBase::invert(n) is called directly.

    Now since that function is not inlined, there is only one single instance of that function (for each type T), rather than one copy for each size n. This stands in stark contrast to the single-class design, where one invert() function would be instantiated for each value of n.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i got an object with contents of html markup in it, for example: string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.