简体   繁体   中英

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. I have to use Visual Studio 2005 (!!) and can't use 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:

#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<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.

Are there any suggestions?

Here follows the code from line 1 to until the line where the problem occurs:

#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. Try std::complex<double> .

Thank you all. The problem has now been resolved. Using the std namespace was indeed the answer but one has to keep in mind the following bug .

After fixing that, everything is working perfectly. Once again,thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM