程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> c/c++»ù´¡(Ê®¾Å) ÓÑÔª

c/c++»ù´¡(Ê®¾Å) ÓÑÔª

編輯:C++入門知識

c/c++»ù´¡(Ê®¾Å) ÓÑÔª


¸ÅÄîµÄ¶«Î÷²»½²ÁË£¬Ö±½ÓÉÏ´úÂ룺


1.ÓÑÔªº¯Êý£º


Point.ÀàµÄÉùÃ÷Ó붨Ò壺

#pragma once
#ifndef _POINT_H
#define _POINT_H

class Point
{
	public:
		void getXY();
		friend double distanceXY(Point &a,Point &b);

	public:
		Point(double x,double y);
		~Point(void);

	private:
		double x;
		double y;
};

#endif

#include "stdafx.h"
#include "Point.h"
#include
#include
using namespace std;

Point::Point(double x,double y)
{
	this->x=x;
	this->y=y;
}


Point::~Point(void)
{
}

void Point::getXY()
{
	cout<<"x: "<
²âÊÔÎļþTestProject.cpp£º

#include "stdafx.h"
#include "Point.h"
#include 
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	Point p1(3.0,4.0),p2(5,6);
	p1.getXY();
	p2.getXY();

	double dis=distanceXY(p1,p2);
	cout<<"distance is : "<
Êä³ö£º

\


¶þ£¬ÓÑÔªÀࣺ


ÀàAµÄÉùÃ÷Ó붨Ò壺

<†·Ÿ"http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vc3Ryb25nPjwvcD4KPHByZSBjbGFzcz0="brush:java;">#pragma once class A { public: void getXY(); friend class B; public: A(double x,double y); ~A(void); private: double x; double y; };



#include "stdafx.h"
#include "A.h"
#include
#include
using namespace std;

A::A(double x,double y)
{
	this->x=x;
	this->y=y;
}


A::~A(void)
{
}

void A::getXY()
{
	cout<<"A x: "<
ÀàBµÄÉùÃ÷Ó붨Ò壺

#pragma once
#include "A.h"
class B
{

public:
	B(void);
	~B(void);

public:
	void setX(A &a);
	void setY(A &b);
};

#include "stdafx.h"
#include "B.h"


B::B(void)
{
}


B::~B(void)
{
}

void B::setX(A &a)
{
	a.x=0;
	a.getXY();
}

void B::setY(A &a)
{
	a.y=0;
	a.getXY();
}

²âÊÔÀàÈçÏ£º

#include "stdafx.h"
#include "A.h"
#include "B.h"
#include 
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	A a(5.0,5.0);
	B b;
	b.setX(a);
	b.setY(a);
	
	return 0;
}

½á¹ûÈçÏ£º

\


Èý£ºÓÑÔªÊÇÀàµÄ³ÉÔ±º¯Êý


MÎļþÉùÃ÷Ó붨Ò壺

#pragma once
#ifndef _M_H
#define _M_H

#include "N.h"
class M
{
	public:
		void getXY();
		friend void N::print(M& m);

	public:
		M(double x,double y);
		~M(void);

	private:
		double x;
		double y;

	private:
		void getXY2();
};

#endif

#include "stdafx.h"
#include "M.h"
#include
#include
using namespace std;

M::M(double x,double y)
{
	this->x=x;
	this->y=y;
}


M::~M(void)
{
}

void M::getXY()
{
	cout<<"M getXY x: "<
NµÄÉùÃ÷Ó붨Ò壺


#pragma once
#ifndef _N_H
#define _N_H

class M;
class N
{

public:
	N(void);
	~N(void);

public:
	void print(M &m);
	void print2(M &m);
};

#endif


#include "stdafx.h"
#include "N.h"
#include "M.h"

N::N(void)
{
}


N::~N(void)
{
}

void N::print(M &m)
{
	m.getXY();
	m.getXY2();
}

void N::print2(M &m)
{
	//m.getXY();//--------ÕâÀïÈç¹û´ò¿ª×¢Êͻᱨ´í
	//m.getXY2();
}



²âÊÔÀࣺ

#include "stdafx.h"
#include "M.h"
#include "N.h"
#include 
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	M m(5.0,5.0);
	N n;
	n.print(m);
	n.print2(m);
	return 0;
}

´òÓ¡½á¹û£º

html

http://baike.baidu.com/view/1066547.htm?fr=aladdin

http://www.cnblogs.com/uniqueliu/archive/2011/08/02/2125590.html

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved