0

我已经编辑了以前的帖子以提供更完整的问题:

我有一个名为 Heliostat 的类,我想在头文件中创建 5 个对象。其中 3 个来自类向量,其中 2 个来自类目标。向量类构造函数需要作为运算符目标对象或向量对象。我收到错误,程序无法将运算符识别为任何类型。我会给你代码。我在 Eclipse 中为一个 arduino 项目工作。

这是定日镜类标题:

    #ifndef HELIOSTAT_H_
    #define HELIOSTAT_H_

    #include "Target.h"
    #include "TargetCatalog.h"
    #include "vector.h"
    #include "Sun.h"



    class Heliostat {


    private:


    public:

        double Pitch;
        double Azimuth;

        Target heliostat(4501472.0,662766.0,1.0);
        Target reactor(4501474.0,662768.0,30.0);
        Vector sunsVec(Sun::getPitch1year(),Sun::getAzimuth1yearArcsin());
        Vector reactVec(heliostat,reactor);
        Vector normalVec(reactVec,sunsVec);

        Heliostat();
        virtual ~Heliostat();

    };

    #endif /* HELIOSTAT_H_ */

它将具有一些不知道的功能。cpp 几乎什么都没有,只有空的构造函数。

目标类头:

    #ifndef TARGET_H_
#define TARGET_H_

class Target {

private:


public:
    enum targetlist{Helio,React,Normalpoint};

    double gpsX;
    double gpsY;
    double gpsZ;

    Target(double gpsEast, double gpsNorth, double gpsAlt);
    virtual ~Target();
};

#endif /* TARGET_H_ */

向量类头:

    #ifndef VECTOR_H_
#define VECTOR_H_

#include "Target.h"

class Vector {
public:

    double easting;
    double northing;
    double altitude;


    Vector(Target startTarget,Target endTarget);
    Vector(double targetsPitch,double targetsAzimuth);
    Vector(Vector reactorVector,Vector sunVector);
    double calculateInclinationAngle(Vector reactorVector,Vector sunVector);
    double getPitch(Vector helioNormalVec);
    double getAzimuth(Vector helioNormalVec);
    virtual ~Vector();

};

#endif /* VECTOR_H_ */

和vector.cpp:

#include "vector.h"
#include "Maths.h"
#include "Target.h"
//vector::vector() {
//  // TODO Auto-generated constructor stub
//
//}

vector::vector(Target startTarget, Target endTarget) {
    double eastingTemp=endTarget.gpsX-startTarget.gpsX;
    double northingTemp=endTarget.gpsY-startTarget.gpsY;
    double altitudeTemp=endTarget.gpsZ-startTarget.gpsZ;
    double vecMagnitude=sqrt(pow(eastingTemp,2)+pow(northingTemp,2)+pow(altitudeTemp,2));
    easting=eastingTemp/vecMagnitude;
    northing=northingTemp/vecMagnitude;
    altitude=altitudeTemp/vecMagnitude;
}

vector::vector(double targetsPitch, double targetsAzimuth) {

    easting=Maths::cosDeg(targetsPitch)*Maths::sinDeg(targetsAzimuth);
    northing=Maths::cosDeg(targetsPitch)*Maths::cosDeg(targetsAzimuth);
    altitude=Maths::sinDeg(targetsPitch);
}

vector::vector(vector normReactorVec, vector normSunVec) {

    double inclinationAngle=calculateInclinationAngle(normReactorVec,normSunVec);
    double normalMagnitude=2*Maths::cosDeg(inclinationAngle);
    easting=(normReactorVec.easting+normSunVec.easting)/normalMagnitude;
    northing=(normReactorVec.northing+normSunVec.northing)/normalMagnitude;
    altitude=(normReactorVec.altitude+normSunVec.altitude)/normalMagnitude;
}

double vector::calculateInclinationAngle(vector reactorVector,vector sunVector) {

    double angleResult=(reactorVector.easting*sunVector.easting)
            + (reactorVector.northing*sunVector.northing)
            + (reactorVector.altitude*reactorVector.altitude);
    double inclinationAngleDoubled=Maths::arccos(angleResult);
    double inclinationAngle=inclinationAngleDoubled/2.0;
    return inclinationAngle;
}

double vector::getPitch(vector helioNormalVec) {
    double pitch=Maths::arcsin(helioNormalVec.altitude);
    if (pitch<0){
        pitch=0;
        Serial.println(F("error on pitch calc"));
    }
    return pitch;
}

double vector::getAzimuth(vector helioNormalVec) {

    double pitch=getPitch(helioNormalVec);
    double theta=Maths::arcsin(helioNormalVec.easting/Maths::cosDeg(pitch));
    //taking absolute of theta function abs() get only int as operators
    if (theta<0){
        theta=-theta;
    }

    double azimuth;
    if (helioNormalVec.easting>0){
        if(helioNormalVec.northing>0){
            azimuth=theta;
        }else if(helioNormalVec.northing<0){
            azimuth=180-theta;
        }else{
            azimuth=90;
        }
    }else if(helioNormalVec.easting<0){
        if(helioNormalVec.northing>0){
            azimuth=360-theta;
        }else if(helioNormalVec.northing<0){
            azimuth=180+theta;
        }else{
            azimuth=270;
        }
    }else{
        if(helioNormalVec.northing>0){
            azimuth=0;
        }else if(helioNormalVec.northing<0){
            azimuth=180;
        }else{
            Serial.println(F("error on Azimuth calc"));
        }
    }
    return azimuth;
}

vector::~vector() {
    // TODO Auto-generated destructor stub
}

关于 sun 类,我只使用 2 个返回双精度值的函数。在这个位置没有草图我不希望程序做一些我正在验证它的语法错误的事情。

我得到的错误说:

'Sun::getPitch1year' is not a type

这同样适用于:getAzimuth1yearArcsin()、TargetCatalog::r​​ectorTarget、TargetCatalog::heliostatTarget、reactVec、sunsVec。对于定日镜头的第一行。

Target heliostat(4501472.0,662766.0,1.0); 
Target reactor(4501474.0,662768.0,30.0);

我收到语法错误,上面写着:数字常量之前应为“,”或“...”

这些问题有什么解决办法吗?

4

1 回答 1

0

在 heiliostat.h 中,行

Vector sunsVec(Sun::getPitch1year(),Sun::getAzimuth1yearArcsin());

声明了一个名为 sunsVec 的函数,并且应该声明它采用什么类型。当前代码尝试调用两个函数。

将 Sun::getPitch1year() 替换为函数返回的类型,并对 Sun::getAzimuth1yearArcsin() 执行相同操作)

于 2013-07-02T02:33:25.187 回答