ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

C错误:’Line2’尚未声明

2019-09-30 00:05:42  阅读:216  来源: 互联网

标签:c codeblocks


C:\CodeBlocks\kool\praks2\src..\include\circle2.h|8|error:
‘Line2’ does not name a type|
C:\CodeBlocks\kool\praks2\src..\include\circle2.h|17|error:
‘Line2’ has not been declared| ||===
Build finished: 2 errors, 0 warnings
===|

circle2.h:

#ifndef CIRCLE2_H
#define CIRCLE2_H

#include "geometry.h"

class Circle2 {
    public:
        Vector2 p1;
        float r;

        Circle2();
        Circle2(Vector2 np1, float nr);
        float circumference();
        float area();
        bool contains(Vector2 v);
        bool contains(Line2 l);  // error is here.
        void scale(float factor);
        friend ostream& operator <<(ostream& out, const Circle2& cir);

};

#endif // CIRCLE2_H

circle.cpp:

bool Circle2::contains(Line2 l) {
    return 0;
}

geometry.h:

#ifndef GEOMETRY_H
#define GEOMETRY_H

// These are needed to use the functions in our library
#include <iostream>
using namespace std;

// Include own headers
// NB! Add your own headers here!
#include "vector2.h"
#include "line2.h"
#include "circle2.h"


#endif // GEOMETRY_H

这是circle2.cpp:

#include "../include/circle2.h"
#include <math.h>


Circle2::Circle2() {
    p1 = Vector2();
    r = 0;
}

Circle2::Circle2(Vector2 np1, float nr) {
    p1 = np1;
    r = nr;
}

float Circle2::circumference() {
    return 2 * r * M_PI;
}
float Circle2::area() {
    return pow(r, 2) * M_PI;
}
bool Circle2::contains(Vector2 v) {
    if(p1.distanceFrom(v) <= r) return 1;
    return 0;
}
bool Circle2::contains(Line2 l) {
    return 0;
}
void Circle2::scale(float factor) {
    r *= factor;
}
ostream& operator<<(ostream& out, const Circle2& cir) {
    out << "(" << cir.p1 << ", " << cir.r << ")";
    return out;
}

line2.cpp:

    #include "../include/line2.h"
#include <math.h>


Line2::Line2() {
    p1 = Vector2();
    p2 = Vector2();
}

Line2::Line2(Vector2 np1, Vector2 np2) {
    p1 = np1;
    p2 = np2;
}

float Line2::length() {
    return p1.distanceFrom(p2);
}

ostream& operator<<(ostream& out, const Line2& line) {
    out << "(" << line.p1 << " - " << line.p2 << ")";
    return out;
}

line2.h:

    #ifndef LINE2_H
#define LINE2_H

#include "geometry.h"

class Line2 {

    public:
        Vector2 p1;
        Vector2 p2;

        Line2();
        Line2(Vector2 np1, Vector2 np2);
        float length();
        friend ostream& operator <<(ostream& out, const Line2& line);
};
#endif // LINE2_H

解决方法:

你可以尝试添加:

class Line2;

之前

class Circle2 {

标签:c,codeblocks
来源: https://codeday.me/bug/20190929/1833959.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有