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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:49:30+00:00 2026-05-23T14:49:30+00:00

The code in question is as follows: header: class Vec3d : public Object {

  • 0

The code in question is as follows:

header:


  class Vec3d : public Object {
    public:
      static linearalgebra::Vec3d* X_AXIS;
      static linearalgebra::Vec3d* Y_AXIS;
      static linearalgebra::Vec3d* Z_AXIS;
      static linearalgebra::Vec3d* AXES[3];

      static int f();
  };

implementation:

  Vec3d* Vec3d::X_AXIS = new Vec3d();
  Vec3d* Vec3d::Y_AXIS = new Vec3d();
  Vec3d* Vec3d::Z_AXIS = new Vec3d();
  Vec3d* Vec3d::AXES[3] = {Vec3d::X_AXIS, new Vec3d(),Vec3d::Z_AXIS};

int Vec3d::f() { X_AXIS = AXES[2]; }

Is there a way of not using these new() operators, but without adding any new helper variables?

The types must be exactly as they are, to be compatible with the rest of the program.

EDIT: guessing from the answers, new() must be used if no helper variables are used. Is it true? Thus, I might add the helper variables. This is a compiler--generated code anyway, so no problem, as long as the headers are readable.

Would the following be ok? Now Valgrind says there are no leaks.


  static Vec3d INIT_X_AXIS;
  static Vec3d INIT_Y_AXIS;
  static Vec3d INIT_Z_AXIS;
  static Vec3d INIT_AXES_1;

  Vec3d* Vec3d::X_AXIS = &INIT_X_AXIS;
  Vec3d* Vec3d::Y_AXIS = &INIT_Y_AXIS;
  Vec3d* Vec3d::Z_AXIS = &INIT_Z_AXIS;
  Vec3d* Vec3d::AXES[3] = {Vec3d::X_AXIS, &INIT_AXES_1, Vec3d::Z_AXIS};
  • 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-23T14:49:30+00:00Added an answer on May 23, 2026 at 2:49 pm

    Is it ok in C++, if these pointers are never freed?

    Define “OK”. Will your program function? Yes. Is it a good idea? No!

    It seems to me that you would be better off with this:

    class Vec3d : public Object {
    public:
        static linearalgebra::Vec3d xAxisMemory;
        static linearalgebra::Vec3d yAxisMemory;
        static linearalgebra::Vec3d zAxisMemory;
        static linearalgebra::Vec3d axesMemory[3];
    
        static linearalgebra::Vec3d* X_AXIS;
        static linearalgebra::Vec3d* Y_AXIS;
        static linearalgebra::Vec3d* Z_AXIS;
        static linearalgebra::Vec3d* AXES[3];
    
        static int f();
    };
    
    
    Vec3d Vec3d::xAxisMemory;
    Vec3d Vec3d::xAxisMemory;
    Vec3d Vec3d::xAxisMemory;
    Vec3d Vec3d::axesMemory[3];
    
    Vec3d* Vec3d::X_AXIS = &xAxisMemory;
    Vec3d* Vec3d::Y_AXIS = &yAxisMemory;
    Vec3d* Vec3d::Z_AXIS = &zAxisMemory;
    Vec3d* Vec3d::AXES[3] = {&axesMemory[0], &axesMemory[1], &axesMemory[2]};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's some code (full program follows later in the question): template <typename T> T
Follow up to this question . I have the following code: string[] names =
This isn't a code question for once, but it definitely has me confused. Basically,
This is more of a licencing issue than a code question. I really like
The code in question is here: var $item = $(this).parent().parent().find('input'); What is the purpose
In answering this code golf question , I ran across a problem in my
This is a code review question more then anything. I have the following problem:
I apologize for making my first question not the hard-hitting code-related question I was
Note : The code in this question is part of deSleeper if you want
I have small page, it looks follows: Some header Label with text only for

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.