1234567890 for dummies

A room to help my dummy friend
4643d ago – jtbadn
695
3

export all events for this room

Starred posts

Nov 7, 2012 20:37
// friend_functions.cpp
// compile with: /EHsc
#include <iostream>

using namespace std;
class Point
{
	//Declaration of Friend Method
    friend void ChangePrivate( Point & );
public:
	//Constructor
    Point( void ) : m_i(0) {}
	// Prints the value of the Private Property
    void PrintPrivate( void ){cout << m_i << endl; }

private:
	// private Property... if you do Point.m_i it would break on you.
    int m_i;
};

// Notice that this is outside the scope of the Class?  Yet you still have access to the private property
Nov 7, 2012 16:04
// friend functions
#include <iostream>
using namespace std;

class CRectangle {
    int width, height;
  public:
    void set_values (int, int);
    int area () {return (width * height);}
    friend CRectangle duplicate (CRectangle);
};

void CRectangle::set_values (int a, int b) {
  width = a;
  height = b;
}

CRectangle duplicate (CRectangle rectparam)
{
  CRectangle rectres;
  rectres.width = rectparam.width*2;
  rectres.height = rectparam.height*2;
  return (rectres);
}

int main () {
  CRectangle rect, rectb;
Nov 7, 2012 16:03
// friend_functions.cpp
// compile with: /EHsc
#include <iostream>

using namespace std;
class Point
{
    friend void ChangePrivate( Point & );
public:
    Point( void ) : m_i(0) {}
    void PrintPrivate( void ){cout << m_i << endl; }

private:
    int m_i;
};

void ChangePrivate ( Point &i ) { i.m_i++; }

int main()
{
   Point sPoint;
   sPoint.PrintPrivate();
   ChangePrivate(sPoint);
   sPoint.PrintPrivate();
}
Nov 6, 2012 22:26
your return 0; is definitely in the wrong place, because nothing after that statement will be executed
Nov 6, 2012 21:45
Well, I have a lot to learn I know that @allquixotic