如何在Visual Studio 2005(C ++)中声明复杂变量

时间:2015-05-22 17:27:31

标签: c++ asp.net .net web-services visual-studio

我正在尝试开发和部署 ASP.NET Web服务作为大学项目的一部分。我必须使用 Visual Studio 2005 (!!)并且不能使用WCF。这些是教授施加的限制。

问题是我必须声明并使用复杂变量。也就是说,一个具有实部和虚部的变量。如果我包含复数,然后将变量声明为:

#include <complex>

然后在代码中输入几行:

complex  waterheater_actual_power;

尝试构建项目时收到以下错误消息:

1>WHeaterImpl.cpp
1>.\WHeaterImpl.cpp(89) : error C2146: syntax error : missing ';' before identifier 'waterheater_actual_power'
1>.\WHeaterImpl.cpp(89) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\WHeaterImpl.cpp(89) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

经过一番搜索后,我遇到了以下post

因此,我像以前一样包含复合体,然后以这种方式声明我的变量:

complex<double>  waterheater_actual_power;

根据我的理解,这应该是解决问题的方法,但在尝试构建项目时,我仍然会收到一些错误消息但这次数量较少。这里确切的是输出:

1>WHeaterImpl.cpp
1>.\WHeaterImpl.cpp(89) : error C2143: syntax error : missing ';' before '<'
1>.\WHeaterImpl.cpp(89) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

此时我应该声明我在视觉工作室中非常新手,所以我不能排除我的问题的答案是非常简单的可能性。

有什么建议吗?

以下是第1行到代码发生之前的代码:

#include <complex>
//#include "WHeater.h"
#include "stdafx.h"
#include "WHeaterImpl.h"
#include "Global.asax.h"


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <iostream>

#define TS_NEVER ((int)(((unsigned int)-1)>>1))
#define TSTAT_PRECISION 0.01
#define HEIGHT_PRECISION 0.01
#define TS_SECOND ((int)1000000000) /* duration of one second */


#define RHOWATER    (62.4)            // lb/cf
#define CFPGAL        (0.133681)        // cf/gal
#define GALPCF        (7.4805195)        // gal/cf
#define CWATER        (0.9994)        // BTU/lb/F
#define BTUPHPW        (3.4120)        // BTUPH/W
#define BTUPHPKW    (1e3 * 3.4120)        // BTUPH/kW
#define KWPBTUPH    (1e-3/BTUPHPW)    // kW/BTUPH
#define MWPBTUPH    (1e-6/BTUPHPW)    // MW/BTUPH
#define ROUNDOFF    1e-6            // numerical accuracy for zero in float comparisons

const double pi = 3.1415926535897931;
const double Cp = 1;                    // Btu/lbm-F

/* approximate tests */
#define AEQ(A,B,C) (fabs(A-B)<C)
#define ANE(A,B,C) (fabs(A-B)>=C)
#define ALT(A,B,C) (A<=B+C)
#define AGT(Ak,B,C) (A>=B-C)

#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))

// Basic characteristics defined at creation...
double Tset_curtail;            ///< lower limit before we cancel curtailment [F]
double Tinlet;                    ///< default will be set to 60 degF
//enumeration location;            ///< location of tank (inside or garage) [enum]
//    enumeration heat_mode;                ///< method of heating the water (gas or electric) [enum]

// Characteristics calculated from basics at creation...
double area;                    ///< tank cross-sectional area [ft^2]
double height;                    ///< tank height [ft]
double Ton;                        ///< cut-in temperature [F]
double Toff;                    ///< cut-out temperature [F]
double Cw;                        ///< thermal mass of water [Btu/F]

// The primary values we compute in our simultation...
double h;                        ///< boundary between hot and cold water layers [ft from top of tank]
double Tlower;                    ///< temperature in lower zone of tank (for 2-zone model) [F]
double Tlower_old;
double Tupper;                    ///< temperature in upper zone of tank (for 2-zone model) [F]
double Tupper_old;
double Twater;                    ///< temperature of whole tank (for 1-node model) [F]
double Tw;                        ///< water temperature [F]
double Tw_old;                    ///< previous water temperature, for internal_gains


double standby_load;
double time_to_transition;        ///< time until next transition [in seconds]

// Convenience values (some pre-computed here and there for efficiency)...
bool heat_needed;                ///< need to maintain this bit of state because of Tstat deadband...
double is_waterheater_on;        ///< Simple logic for determining state of waterheater 1-on, 0-off

double tank_volume;                    ///< tank size [gal]
double tank_UA;                        ///< tank UA [BTU/hr-F]
double tank_diameter;                ///< tank diameter [ft]
double water_demand;                ///< water draw rate [gpm]
double water_demand_old;            ///< previous water demand, needed for temperature change (reflects heat loss from hot water draw)
double heating_element_capacity;    ///< rated Q of (each) heating element, input in W, converted to[Btu/hr]
double tank_setpoint;                ///< setpoint T of heating element [F]
double thermostat_deadband;            ///< deadband around Tset (half above, half below) [F]
double *pTair;
double *pTout;

double gas_fan_power;        ///< fan power draw when a gas waterheater is burning fuel
double gas_standby_power;    ///< standby power draw when a gas waterheater is NOT burning fuel

double actual_load;
double prev_load;
complex<double> waterheater_actual_power;

2 个答案:

答案 0 :(得分:1)

complex标头中定义的complex类模板位于std命名空间中。试试std::complex<double>

答案 1 :(得分:0)

谢谢大家。问题现在已经解决了。使用std命名空间确实是答案,但必须牢记以下bug

修好之后,一切都运转良好。 再一次,谢谢你。