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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:06:37+00:00 2026-06-07T03:06:37+00:00

I have a class: class Point3D : public Point{ protected: float x; float y;

  • 0

I have a class:

class Point3D : public Point{
    protected:
        float x;
        float y;
        float z;

    public:
        Point3D(){x=0; y=0; z=0;}
        Point3D(const Point3D & point){x = point.x; y = point.y; z = point.z;} 
        Point3D(float _x,float _y,float _z){x = _x; y = _y; z = _z;}

        inline const Point3D operator+(const Vector3D &);

        const Point3D & operator+(const Point3D &point){
            float xT = x + point.getX();
            float yT = y + point.getY();
            float zT = z + point.getZ();
            return Point3D(xT, yT, zT);
        }
...

When I use it that way:

Point3D point = Point3D(10,0,10);

Everything works fine.

When I write:

Point3D point = Point3D(10,0,10);
Point3D point2 = Point3D(0,0,0) + point();

Also it’s ok (point2 = point). When I add something more than (0,0,0) it’s also working.

But when I want just to:

Point3D point = Point3D(10,0,10);
someFunction( Point3D(0,0,0) + point ); //will get strange (x,y,z)

The function get value of some (in my opinion) random (x,y,z). Why?

What’s even stranger, in that similar example everything will be working again:

Point3D point = Point3D(10,0,10);
Point3D point2 = Point3D(0,0,0) + point;
someFunction( point2 );  // will get (10,0,10)

What’s the reason for that strange behaviour?

  • 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-07T03:06:39+00:00Added an answer on June 7, 2026 at 3:06 am

    The operator+() is returning a dangling reference, the returned reference is referring to a Point3D instance that is destroyed when operator+() returns. Change to:

    Point3D operator+(const Point3D &point) const {
    

    so a copy is returned, and make it const as it has no reason to be changing anything.

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

Sidebar

Related Questions

I have the code: class Point3D{ protected: float x; float y; float z; public:
I have the code: class Vector3D : public Vector{ protected: Point3D * start; Point3D
Case One Say you have a little class: class Point3D { private: float x,y,z;
I have a Node class: public class Node { private string name; private Point3D
I have a Point2D class as follows: class Point2D{ int x; int y; public:
I have class with back reference: public class Employee : Entity { private string
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have a class: public class PointD { public double X { get; set;
I have this class class Point2D { public: bool isValid(); // ... private: double
I have a class Drawview: public class DrawView extends View { private ColorBall[] colorballs

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.