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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:48:13+00:00 2026-05-31T23:48:13+00:00

so I was writing some matrix classes in C++. So each matrix has a

  • 0

so I was writing some matrix classes in C++. So each matrix has a pointer to an array called entries, I am not sure if i’m doing this right but I am redeclaring the array in the sub class. (I’m no expert in C++)

Does this memory need to be free’d? Am I simply overwriting the pointer with the referenced array? Any help would be greatly appreciated.
Thanks

class Matrix {
protected:
    float* entries;
public:
    int rows;
    int cols;


    Matrix() {
    }
    ~Matrix() {
    }
};

class Matrix4x4 : public Matrix {
    protected:
        float entry[4][4];
    public:

    /* This will create an empty matrix */
    Matrix4x4() {
        //Define the size of the arrays
        rows = 4;
        cols = 4;
        this->empty();
    }
    ...
};
  • 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-31T23:48:13+00:00Added an answer on May 31, 2026 at 11:48 pm

    The code isn’t leaking memory and cannot possibly do so, since you never say new or malloc anywhere in your code*, nor do you call functions which do so in an unguarded fashion (i.e. outside RAII objects).

    However, the code is also fairly useless and misguided (e.g. Matrix4x4::entry is hiding the vestigial Matrix::entry, and rows and columns seem to be somewhat redundant variables), and that can only be solved by sitting down with a good C++ book for a few hours.

    *) or, as @Nicol Bolas has helpfully pointed out, make_shared together with a lost circular reference

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

Sidebar

Related Questions

I'm writing some documentation in Markdown, and creating a separate file for each section
I am writing an abstract matrix class (and some concrete subclasses) for use on
I am writing a Graph library that has both adjacency list and matrix implementations.
Writing some additional classes for an existing GWT project. I need to: Request a
I'm writing some code to perform some game theory simulations. My world has several
I'm having some trouble writing a hashCode() method for a class I created. This
As part of a larger function, I'm writing some code to generate a vector/matrix
In writing some code today, I have happened upon a circumstance that has caused
Writing some test scripts in IronPython, I want to verify whether a window is
While writing some C code, I decided to compile it to assembly and read

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.