gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:15:36 24 4
gpt4 key购买 nike

我正在尝试开发和部署 ASP.NET 网络服务 作为大学项目的一部分。我必须使用 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,然后以这种方式声明我的变量:

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

在这一点上,我应该声明我在 visual studio 中几乎是新手,所以我不能排除我的问题的答案非常简单的可能性。

有什么建议吗?

下面是从第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;

最佳答案

complex complex 中定义的类模板 header 在 std 中命名空间。尝试 std::complex<double> .

关于c++ - 如何在 Visual Studio 2005 (C++) 中声明复杂变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30402596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com