You should be familiar with the youyuan class. The youyuan class declaration will describe the whole class as the youyuan relationship of another class. All member functions of the youyuan class can be the youyuan function of another class; when I was debugging the program yesterday, when I wrote all the programs in one file, including the implementation of classes and youyuan classes, as well as the main function, which can be compiled and executed, however, when I separate the definition and implementation of classes, the Code is as follows:
Mypoint. h
# Ifndef _ mypoint_h _ # DEFINE _ mypoint_h _ // # include "line. H "// if this line is added here, it will not be compiled. After it is removed, it can be compiled or executed. I don't know why class line; Class mypoint {private: Float X; float y; static int count; public: mypoint ();~ Mypoint (); mypoint (mypoint & Point); mypoint (float X, float y); void display (); friend class line; friend float FDIS (mypoint & P1, mypoint & p2) ;};# endif
Mypoint. cpp
# Include "stdafx. H "# include <iostream> # include <math. h> # include "mypoint. H "using namespace STD; int mypoint: Count = 0; mypoint: mypoint (void) {This-> count ++;} mypoint: mypoint (mypoint & P) {This-> X = P. x; this-> Y = P. y; this-> count ++;} mypoint: mypoint (float X, float y) {This-> X = x; this-> Y = y; this-> count ++;} mypoint ::~ Mypoint (void) {} void mypoint: Display () {cout <"mypoint :(" <this-> x <", "<this-> Y <") "<Endl; cout <"current is the nth" <this-> count <"coordinate point" <Endl;} float FDIS (mypoint & P1, mypoint & p2) {float F1 = p1.x-p2.x; float F2 = p2.y-p2.y; float d = POW (F1, 2) + POW (F2, 2); D = SQRT (d ); return D ;}
Line. h
#ifndef _LINE_H_#define _LINE_H_#include "myPoint.h"class Line{public:Line(){}~Line(){}Line(Line& line);Line(myPoint& pp1, myPoint& pp2);float getLength();private:myPoint p1;myPoint p2;};#endif
Line. cpp
#include "stdafx.h"#include <iostream>#include <math.h>#include "Line.h"using namespace std;Line::Line(Line &line){this->p1 = line.p1;this->p2 = line.p2;}Line::Line(myPoint& pp1, myPoint& pp2){this->p1 = pp1;this->p2 = pp2;}float Line::getLength(){float f1 = this->p1.x - this->p2.x;float f2 = this->p1.y - this->p2.y;float d = pow(f1, 2) + pow(f2, 2);d = sqrt(d);return d;}
Does anyone know why # include "line. H" in mypoint. h cannot be compiled?