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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:06:32+00:00 2026-05-15T19:06:32+00:00

template <typename T> class Table { public: Table(); Table(int m, int n); Table(int m,

  • 0
template <typename T>
  class Table {
    public:
      Table();
      Table(int m, int n);
      Table(int m, int n, const T& value);
      Table(const Table<T>& rhs);
      ~Table();
      Table<T>& operator=(const Table& rhs);
      T& operator()(int i, int j);
      int numRows()const;
      int numCols()const;
      void resize(int m, int n);
      void resize(int m, int n, const T& value);
    private:
      // Make private because this method should only be used
      // internally by the class.
      void destroy();
    private:
      int mNumRows;
      int mNumCols;
      T** mDataMatrix;
  };

template <typename T>
  void Table<T>::destroy() {
    // Does the matrix exist?
    if (mDataMatrix) {
      for (int i = 0; i < _m; ++i) {
        // Does the ith row exist?
        if (mDataMatrix[i]) {
          // Yes, delete it.
          delete[]mDataMatrix[i];
          mDataMatrix[i] = 0;
        }
      }

      // Delete the row-array.
      delete[] mDataMatrix;
      mDataMatrix = 0;
    }

    mNumRows = 0;
    mNumCols = 0;
  }

This is a code sample I got from a book. It demonstrates how to destroy or free a 2×2 matrix where mDataMatrix is the pointer to array of pointers.

What I don’t understand is this part:

for(int i = 0; i < _m; ++i) {
  // Does the ith row exist?
  if (mDataMatrix[i]) {
    //.….

  }
}

I don’t know why the book uses _m for max number of row-ptr. It wasn’t even a variable define in class; the variable for max row is mNumRows. Maybe it is some compiler pre-defined variable? Another thing I am quite confuse is why is it ++i? pre-operator, why not i++? Will it make different if I change it into i++?

  • 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-15T19:06:33+00:00Added an answer on May 15, 2026 at 7:06 pm

    Another thing I am quite confuse is why is it ++i? pre-operator, why not i++? Will it make different if I change it into i++?

    Because ++i is more natural and easier to understand: increment i and then yield the variable i as a result. i++ on the other hand means copy the current value of i somewhere (let’s call it temp), increment i, and then yield the value temp as a result.

    Also, for user-defined types, i++ is potentially slower than ++i.

    Note that ++i as a loop increment does not imply the increment happens before entering the loop body or something. (This seems to be a common misconception among beginners.) If you’re not using ++i or i++ as part of a larger expression, the semantics are exactly the same, because prefix and postfix increment only differ in their result (incremented variable vs. old value), not in their side effect (incrementing the variable).

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

Sidebar

Related Questions

I have a class template <typename Iterator, typename Value> class Foo { public: Foo(const
Consider the following code : template<typename T> class Base { Base(); Base(const Base<T>& rhs);
Because I've overloaded the operator++ for an iterator class template<typename T> typename list<T>::iterator& list<T>::iterator::operator++()
I have a class template <typename T> class C { static const int K=1;
Consider: template <typename T> class Base { public: static const bool ZEROFILL = true;
Why isn't this working: class/struct SomeClass { public: int SomeValue; } template <class/struct/typename T>
This is my template matrix class: template<typename T> class Matrix { public: .... Matrix<T>
template<typename T> class vec3 { public: typename T type_t; T x; T y; T
I have the following class: template <typename T> class matrix { private: int _n;
Given the following template: template <typename T> class wrapper : public T {}; 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.