[英]How to declare a complex variable in Visual Studio 2005 (C++)
i am trying to develop and deploy an ASP.NET web service as part of a university project. 我正在尝试开发和部署ASP.NET Web服务作为大学项目的一部分。 I have to use Visual Studio 2005 (!!) and can't use WCF. 我必须使用Visual Studio 2005 (!!),不能使用WCF。 Those are the restrictions imposed by the professor. 这些是教授施加的限制。
Problem is i have to declare and use a complex variable. 问题是我必须声明并使用一个复杂的变量。 That is, a variable that has a real and an imaginary part.If i include complex and then declare the variable as such: 也就是说,一个变量具有实部和虚部。如果我包含complex,则将其声明为:
#include <complex>
And then several lines later in the code: 然后在代码的后面几行:
complex waterheater_actual_power;
I get the following error messages when trying to build the project: 尝试构建项目时收到以下错误消息:
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
After some search i came accross the following post 经过一番搜索,我遇到了以下帖子
Thus, i include complex as previously and then declare my variable this way: 因此,我像以前一样包含complex,然后以这种方式声明我的变量:
complex<double> waterheater_actual_power;
According to my understanding this should be ebough to resolve the issue but when trying to build the project i still get some error messages but less in number this time. 根据我的理解,解决该问题应该很轻松,但是当尝试构建项目时,我仍然收到一些错误消息,但是这次的数量较少。 To be exact here is the output: 确切地说,这是输出:
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
At this point i should declare that i am pretty much novice in visual studio so i can't rule out the possibility that the answer to my problem is something painfully simple. 在这一点上,我应该声明我是Visual Studio的新手,因此我不排除解决我的问题的方法非常简单。
Are there any suggestions? 有什么建议吗?
Here follows the code from line 1 to until the line where the problem occurs: 下面是从第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;
The complex
class template defined in the complex
header is in the std
namespace. 在complex
头文件中定义的complex
类模板位于std
名称空间中。 Try std::complex<double>
. 尝试std::complex<double>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.