15,901,426 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 Re: Problem with return value of private variable within class Md. Ali Naser Khan25-Mar-09 19:01 Md. Ali Naser Khan 25-Mar-09 19:01
 Re: Problem with return value of private variable within class Michael Randolph25-Mar-09 20:40 Michael Randolph 25-Mar-09 20:40
 Re: Problem with return value of private variable within class Cedric Moonen25-Mar-09 21:14 Cedric Moonen 25-Mar-09 21:14
 Re: Problem with return value of private variable within class Niklas L26-Mar-09 1:25 Niklas L 26-Mar-09 1:25
 Re: Problem with return value of private variable within class Stuart Dootson25-Mar-09 23:41 Stuart Dootson 25-Mar-09 23:41
 Re: Problem with return value of private variable within class Michael Randolph26-Mar-09 19:14 Michael Randolph 26-Mar-09 19:14
 Re: Problem with return value of private variable within class Stuart Dootson26-Mar-09 21:32 Stuart Dootson 26-Mar-09 21:32
 Re: Problem with return value of private variable within class Michael Randolph27-Mar-09 2:40 Michael Randolph 27-Mar-09 2:40
 Thank you so much for your help. Looks like I have a bit of studying to do. I am not totally sure how this works but it does. Here is the fixed source in case someone needs to check it out. ```#include using namespace std; class Point { public: Point(float f_x = 1.0, float f_y = 1.0, float f_z = 1.0); ~Point(); void setXYZ(float X, float Y, float Z); void setX(float X); void setY(float Y); void setZ(float Z); // return by reference void getXYZ(float &X, float &Y, float &Z); float getX() const; float getY() const; float getZ() const; // overloading = operator to deal with pointers Point& operator =(Point const &p); private: float x, y, z; protected: }; // define constructor with args Point::Point(float f_x, float f_y, float f_z) { cout << "We're in the constructor with arguments " << (int)this /*unique identifier*/ << endl; x = f_x; y = f_y; z = f_z; } // define destructor Point::~Point() { cout << "Destructing now!!! " << (int)this /*unique identifier*/ << endl; } // public function to return private value of variable x float Point::getX() const { return x; } // public function to return private value of variable y float Point::getY() const { return y; } // public function to return private value of variable z float Point::getZ() const { return z; } // public function to change value of private variable x void Point::setX(float X) { x = X; } // public function to change value of private variable y void Point::setY(float Y) { y = Y; } // public function to change value of private variable z void Point::setZ(float Z) { z = Z; } // public function to change value of all three private variables void Point::setXYZ(float X, float Y, float Z) { /* slower setX(X); setY(Y); setZ(Z);*/ // faster x = X; y = Y; z = Z; } // public function to return values of x,y,z by reference void Point::getXYZ(float &X, float &Y, float &Z) { X = getX(); Y = getY(); Z = getZ(); } // overloading = operator Point& Point::operator =(Point const &p) { setX(p.getX()); setY(p.getY()); setZ(p.getZ()); // passing back value rather than address return *this; } // overloading operator << (output stream) ostream &operator <<(ostream &stream, Point &p) { stream << p.getX() << " " << p.getY() << " " << p.getZ(); return stream; } // overloading operator >> (input stream) istream &operator >>(istream &stream, Point &p) { float x, y, z; stream >> x >> y >> z; p.setXYZ(x, y, z); return stream; } //------------------------------------------ // Point Class End //------------------------------------------ class Vector : public Point { public: Vector(float X=0, float Y=0, float Z=0); Vector operator +(Vector &p); }; // initiate X, Y, Z from Point Class with : operator Vector::Vector(float X, float Y, float Z) : Point(X, Y, Z) { //anything extra can go here } Vector Vector::operator +(Vector &p) { Vector outV; outV.setX(getX() + p.getX()); outV.setY(getY() + p.getY()); outV.setZ(getZ() + p.getZ()); return outV; } int main() { // instance of the Vector Class Vector vect1(1, 2, 3); Vector vect2(5, 4, 2); Vector vect3; vect3 = vect1 + vect2; cout << vect3 << endl; }```
 How can I remove vertical scrollbar from Microsoft web browser? Md. Ali Naser Khan25-Mar-09 17:54 Md. Ali Naser Khan 25-Mar-09 17:54
 Re: How can I remove vertical scrollbar from Microsoft web browser? [modified] Yajnesh Narayan Behera26-Mar-09 3:35 Yajnesh Narayan Behera 26-Mar-09 3:35
 "game" fast fingers Aljaz11125-Mar-09 8:18 Aljaz111 25-Mar-09 8:18
 Re: "game" fast fingers Cedric Moonen25-Mar-09 8:21 Cedric Moonen 25-Mar-09 8:21
 Re: "game" fast fingers Aljaz11125-Mar-09 8:26 Aljaz111 25-Mar-09 8:26
 Re: "game" fast fingers CPallini25-Mar-09 8:30 CPallini 25-Mar-09 8:30
 Re: "game" fast fingers Aljaz11125-Mar-09 8:40 Aljaz111 25-Mar-09 8:40
 Re: "game" fast fingers CPallini25-Mar-09 8:46 CPallini 25-Mar-09 8:46
 Re: "game" fast fingers led mike25-Mar-09 9:35 led mike 25-Mar-09 9:35
 Re: "game" fast fingers CPallini25-Mar-09 9:50 CPallini 25-Mar-09 9:50
 Re: "game" fast fingers ThatsAlok25-Mar-09 17:44 ThatsAlok 25-Mar-09 17:44
 Re: "game" fast fingers Aljaz11125-Mar-09 9:45 Aljaz111 25-Mar-09 9:45
 Re: "game" fast fingers led mike25-Mar-09 10:02 led mike 25-Mar-09 10:02
 Re: "game" fast fingers Cedric Moonen25-Mar-09 21:07 Cedric Moonen 25-Mar-09 21:07
 Re: "game" fast fingers led mike26-Mar-09 5:35 led mike 26-Mar-09 5:35
 Re: "game" fast fingers CPallini25-Mar-09 10:09 CPallini 25-Mar-09 10:09
 Re: "game" fast fingers Aljaz11125-Mar-09 10:25 Aljaz111 25-Mar-09 10:25
 Last Visit: 31-Dec-99 18:00     Last Update: 19-May-24 16:05 Refresh ᐊ Prev1...3295329632973298329933003301330233033304 Next ᐅ