zoukankan      html  css  js  c++  java
  • 关于两个类放入调用,和类未定义前声明的问题

     1 #include<iostream>
     2 #include<cmath>
     3 
     4 //设计一个圆形类(AdvCircle),和一个点类(Point),计算点在圆内部还是圆外
     5 //    即:求点和圆的关系(圆内和圆外)
     6 using namespace std;
     7 class MyPoint;//类的声明,为了告诉下面定义了这个类。但是这样只能使用类的引用和指针。
     8 
     9 
    10 class AdvCircle
    11 {
    12 public:
    13     double a_x0;
    14     double a_y0;
    15     double ap_distance;
    16     double a_r;
    17 public:
    18     void getXY(double x0,double y0,double r)
    19     {
    20         a_x0=x0;
    21         a_y0=y0;
    22         a_r=r;
    23     }
    24     double judge(MyPoint &mpt)//引用实际上就是传入自己的点,这里是自己的盲点,要多加注意
    25     {
    26         if( a_r*a_r  <=  (mpt.p_x1-a_x0)*(mpt.p_x1-a_x0) + (mpt.p_y1-a_y0)*(mpt.p_y1-a_y0) )
    27             return 1;
    28         else 
    29             return 0;
    30     } 
    31 };
    32 class MyPoint
    33 {
    34 public:
    35     double p_x1;
    36     double p_y1;
    37 public:
    38     void getXY(double x1,double y1)
    39     {
    40         p_x1=x1;
    41         p_y1=y1;
    42     }
    43 };
    44 
    45 int main()
    46 {
    47     AdvCircle m1;
    48     MyPoint p1;
    49     m1.getXY(1.3,2.0,4.0);
    50     p1.getXY(2.0,3.0);
    51     double tag=m1.judge(p1);
    52     if(tag==0)
    53     cout<<"在圆外 /n";
    54     else
    55         cout<<"在园内/n";
    56     system("pause");
    57 }

    这样子的类日前声明是不对的。要把MyPoint的类提前就可以了

  • 相关阅读:
    Swift-自定义类的构造函数
    Swift-存储属性,计算属性,类属性
    iOS-UICollectionViewController协议及回调
    Swift-数组
    Swift-switch使用注意点
    Swift-setValuesForKeysWithDictionary
    解决IDEA Struts2 web.xml问题
    枚举类
    增强for循环 -- foreach循环
    静态导入
  • 原文地址:https://www.cnblogs.com/xiaochige/p/6550399.html
Copyright © 2011-2022 走看看