求大神帮我看看C++代码

以下是我的.h头文件:

 #include <vector>
#include<iostream>
#include <iomanip>
#include <math.h>
#define M_PI  3.14159265359

////////**************定义目标状态***************////////


typedef struct strTargetState//笛卡尔坐标系位置
{
    double dTargetPostionX;//x
    double dTargetPostionY;//y
    double dTargetPostionZ;//z
}strTargetState;

vector <strTargetState> vTargetState;

//////////*************定义传感器位置*************///////

typedef struct strSensorLocate//笛卡尔坐标系位置
{
    double dSensorX;//x
    double dSensorY;//y
    double dSensorZ;//z
}strSensorLocate;

strSensorLocate strSensor1;
strSensorLocate strSensor2;
strSensorLocate strSensor3;
strSensorLocate strSensor4;


//////////*************计算极坐标下位置*************//////

typedef struct strTargetPolarCoordinate//极坐标下位置
{
    double dTargetPitch;//俯仰角 phi
    double dTargetAzimuth;//方位角 thita
    double dTargetR;//径向距离 r
}strTargetPolarCoordinate;

strTargetPolarCoordinate strTargetPolar;

class CHuoPaoSheng721//class declaration
{
public:
    CHuoPaoSheng721(double dIvestiRg,double dFrequency,double dDetectAccur,double dMornitScope,double dDataUpdateRate,
        int nMaxTargetNum,bool bDamageSatus,bool bOnOffControl,double dOriginLongitude,double dOriginLatitude,double dOriginHeight,
        double dL,double dh,double dSoundVelocity):

        m_dIvestiRg(dIvestiRg),
        m_dFrequency(dFrequency),
        m_dDetectAccur(dDetectAccur),
        m_dMornitScope(dMornitScope),
        m_dDataUpdateRate(dDataUpdateRate),
        m_nMaxTargetNum(nMaxTargetNum),
        m_bDamageSatus(bDamageSatus),
        m_bOnOffControl(bOnOffControl),

        m_dOriginLongitude(dOriginLongitude),
        m_dOriginLatitude(dOriginLatitude),
        m_dOriginHeight(dOriginHeight),

        m_dL(dL),//传感器坐标
        m_dh(dh),

        m_dSoundVelocity(dSoundVelocity)//声速    
    {
    }//endof CHuoPaoSheng721 构造函数初始化

    ~CHuoPaoSheng721(){}//析构函数

    int get_initia_Para();//系统参数初始化显示
    int sys_state();//系统工作状态判断
    int get_polar();//目标角度量测

private:
    double m_dIvestiRg;//侦查距离
    double m_dFrequency;//传声器范围
    double m_dDetectAccur;//侦查精度
    double m_dMornitScope;//监视范围
    double m_dDataUpdateRate;//数据更新率
    int   m_nMaxTargetNum;//最大检测目标数
    bool  m_bDamageSatus;//毁伤状态 1on 0off
    bool  m_bOnOffControl;//开关机控制 1on 0off

    double m_dOriginLongitude;//坐标原点经度
    double m_dOriginLatitude;//坐标原点纬度
    double m_dOriginHeight;//坐标原点高度

    double m_dL;//传感器坐标
    double m_dh;

    double m_dSoundVelocity;//声速
    double m_dr1;//距离
    double m_dr2;
    double m_dr3;
    double m_dr4;

    double m_dtime1;//到达时间
    double m_dtime2;
    double m_dtime3;
    double m_dtime4;
};//end of class CHuoPaoSheng721

以下是头文件对应的.cpp文件:
#include"stdafx.h"
#include <vector>
#include<iostream>
#include <iomanip>
#include <math.h>
#include "CHuoPaoSheng721.h"
#define M_PI  3.14159265359
using namespace std;

int CHuoPaoSheng721::get_initia_Para()//系统参数初始化显示
{
    cout<<"侦查距离/(km):"<<setw(8)<<m_dIvestiRg<<endl;
    cout<<"传声器频率范围/Hz:"<<setw(8)<<m_dFrequency<<endl;
    cout<<"侦查精度(m):"<<setw(8)<<m_dDetectAccur<<endl;
    cout<<"监视范围:"<<setw(8)<<m_dMornitScope<<endl;
    cout<<"数据更新率:"<<setw(8)<<m_dDataUpdateRate<<endl; 
    cout<<"最大检测目标数:"<<setw(8)<<m_nMaxTargetNum<<endl;
    return 0;
}//end of get_initia_Para

int CHuoPaoSheng721::sys_state()//系统工作状态判断
{
    if ((m_bDamageSatus==1) && (m_bOnOffControl==1))
    {
        cout<<"系统正常可进行有效侦查"<<endl;
    }
    else
    {
        if (m_bDamageSatus==0)
        {
            cout<<"系统毁伤"<<endl;
        }
        if (m_bOnOffControl==0)
        {
            cout<<"系统未开机"<<endl;
        }
    }//end of if
    return 0;
}//end of CParaInitia

int CHuoPaoSheng721::get_polar()
{

//////////*************定义传感器位置*************/////////


    strSensor1.dSensorX=m_dL;
    strSensor1.dSensorY=0;
    strSensor1.dSensorZ=m_dh;

    strSensor2.dSensorX=-m_dL;
    strSensor2.dSensorY=0;
    strSensor2.dSensorZ=m_dh;

    strSensor3.dSensorX=0;
    strSensor3.dSensorY=-m_dL;
    strSensor3.dSensorZ=m_dh;

    strSensor4.dSensorX=0;
    strSensor4.dSensorY=m_dL;
    strSensor4.dSensorZ=0;

    //  m_vTargetState.push_back(m_vTargetState);目标状态获得 压入数值

///////////**********火炮声计算************////////////


    for (int i=0;i<vTargetState.size();i++)
    {       
        m_dr1=sqrt(pow(strSensor1.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor1.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor1.dSensorZ-vTargetState[i].dTargetPostionZ,2));
        m_dr2=sqrt(pow(strSensor2.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor2.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor2.dSensorZ-vTargetState[i].dTargetPostionZ,2));
        m_dr3=sqrt(pow(strSensor3.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor3.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor3.dSensorZ-vTargetState[i].dTargetPostionZ,2));
        m_dr4=sqrt(pow(strSensor4.dSensorX-vTargetState[i].dTargetPostionX,2)+pow(strSensor4.dSensorY-vTargetState[i].dTargetPostionY,2)+pow(strSensor4.dSensorZ-vTargetState[i].dTargetPostionZ,2));

        if(((m_dIvestiRg>m_dr1)&&(m_dIvestiRg>m_dr2)&&(m_dIvestiRg>m_dr3)&&(m_dIvestiRg>m_dr4))==0)
        {   
            cout<<"目标超出传感器探测范围"<<endl;
            continue;
        }       

        m_dtime1=m_dr1/m_dSoundVelocity;
        m_dtime2=abs(m_dr2-m_dr1)/m_dSoundVelocity;
        m_dtime3=abs(m_dr4-m_dr1)/m_dSoundVelocity;
        m_dtime4=abs(m_dr4-m_dr1)/m_dSoundVelocity;

        strTargetPolar.dTargetAzimuth=atan((m_dtime3-m_dtime4)/m_dtime2)/M_PI*180;
        strTargetPolar.dTargetPitch=acos(m_dSoundVelocity*sqrt(pow(m_dr2,2)+pow(m_dr3-m_dr4,2)/(2*m_dL)));
        strTargetPolar.dTargetR=(pow(m_dL,2)*(m_dtime2-m_dtime3-m_dtime4)-pow(m_dL,2)*sqrt(4*pow(m_dL,2)/pow(m_dSoundVelocity,2)-pow(m_dtime2,2)-pow(m_dtime3-m_dtime4,2)))/(m_dSoundVelocity*(pow(m_dtime2,2)+pow(m_dtime2-m_dtime3-m_dtime4,2)-4*pow(m_dL,2)/pow(m_dSoundVelocity,2)));
    }

    cout<<"目标方位角为:"<<strTargetPolar.dTargetAzimuth<<endl;
    cout<<"目标俯仰角为:"<<strTargetPolar.dTargetPitch<<endl;
    cout<<"目标径向距为:"<<strTargetPolar.dTargetR<<endl;

    return 0; 
}//end of get_polar

编译的时候报错:
--------------------Configuration: huo_pao_sheng721 - Win32 Debug--------------------
Compiling...
CHuoPaoSheng721.cpp
d:\vc6.0\msdev98\myprojects\huo_pao_sheng721\chuopaosheng721.h(17) : error C2143: syntax error : missing ';' before '<'
d:\vc6.0\msdev98\myprojects\huo_pao_sheng721\chuopaosheng721.h(17) : error C2501: 'vector' : missing storage-class or type specifiers
d:\vc6.0\msdev98\myprojects\huo_pao_sheng721\chuopaosheng721.h(17) : error C2143: syntax error : missing ';' before '<'
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(68) : error C2065: 'vTargetState' : undeclared identifier
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(68) : error C2228: left of '.size' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(70) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(71) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(72) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionX' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionY' must have class/struct/union type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2109: subscript requires array or pointer type
D:\VC6.0\MSDev98\MyProjects\huo_pao_sheng721\CHuoPaoSheng721.cpp(73) : error C2228: left of '.dTargetPostionZ' must have class/struct/union type
Error executing cl.exe.

huo_pao_sheng721.exe - 29 error(s), 0 warning(s)

有好多是关于vector的,应该怎么改呢,怎么调通程序呢,小白真的不会了。大神们请帮帮忙。

5个回答

自己解决了,少了using namespace std; 好笨。。。

你每个结构体都缺少后花括号 }
怎么搞的。

u014556237
zoefun 有后花括号的呀~
大约 5 年之前 回复

你的vector没有加类型,例如:
把vector vTargetState;
改成:vector vTargetState;

lpfly
lpfly 回复zoefun: 把.h头文件里的vector改成std::vector,或者在.h里加using namespace std;
大约 5 年之前 回复
lpfly
lpfly 回复zoefun: 你没有用std namespace,把vector<...>改成:std::vector<...>
大约 5 年之前 回复
u014556237
zoefun 回复lpfly: 改了,可报错还是一模一样的。
大约 5 年之前 回复
lpfly
lpfly 不好意思,打错了。改成:vector<strTargetState> vTargetState;
大约 5 年之前 回复

大神们,看过来啊~~~···

 typedef struct __strTargetState//笛卡尔坐标系位置
{
    double dTargetPostionX;//x
    double dTargetPostionY;//y
    double dTargetPostionZ;//z
}strTargetState;

结构体加个别名试试

oyljerry
oyljerry 回复zoefun: 具体错误行数对应的代码是?
大约 5 年之前 回复
u014556237
zoefun 改了还是一样的报错。。。哭了。。
大约 5 年之前 回复
u014556237
zoefun 什么意思?加别名?
大约 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐