2012-04-19 57 views
0

我使用Visual Studio 2010與C++,儘管將預編譯頭文件選項設置爲'不使用預編譯頭文件',但它仍然堅持忽略頭文件。在另一臺機器上,使用相同的設置可以正常工作。我怎樣才能解決這個問題?Visual Studio 2010不構建頭文件更新

Complex.h

#include <cmath> 
#include <cstdlib> 
using namespace std; 

class Complex{ 

private: 
    double real, imaginary, magnitude, angle; 
    double rectangularToMagnitude(double, double); 
    double rectangularToAngle(double, double); 
    double polarToReal(double, double); 
    double polarToImaginary(double, double); 
public: 
    Complex (char, double, double); 
    Complex (double, double); 
    Complex (double); 
    Complex(); 

    double getReal(); 
    double getImaginary(); 
    double getMagnitude(); 
    double getAngle(); 

    void setRectangular(double, double); 
    void setPolar(double, double); 
}; 

Complex.cpp

#include "Complex.h" 

// Three arguments passed, type and variables. 
Complex::Complex(char type, double a, double b) 
{ 
    switch(type) 
    { 
    case 'R': 
    case 'r': 
     setRectangular(a, b); 
     break; 
    case 'P': 
    case 'p': 
     setPolar(a, b); 
     break; 
    } 
} 

// Two arguments passed, assume rectangular. 
Complex::Complex (double a, double b) 
{ 
    real = a; 
    imaginary = b; 
    magnitude = rectangularToMagnitude(a, b); 
    angle = rectangularToAngle(a, b); 
} 

// One argument passed, assume real, used to cast double to complex. 
Complex::Complex (double a) 
{ 
    real = a; 
    imaginary = 0; 
    magnitude = a; 
    angle = 0; 
} 

// No argument passed, assume values of zero. 
Complex::Complex() 
{ 
    real = 0; 
    imaginary = 0; 
    magnitude = 0; 
    angle = 0; 
} 

// Convert real to imaginary and vice versa. 
double Complex::rectangularToMagnitude(double re, double im) {return sqrt((re*re)+(im*im));} 
double Complex::rectangularToAngle(double re, double im) {return atan2(im, re);} 
double Complex::polarToReal(double ma, double an) {return ma*cos(an);} 
double Complex::polarToImaginary(double ma, double an) {return ma*sin(an);} 

// Accessors 
double getReal() {return real;} 
double getImaginary() {return imaginary;} 
double getMagnitude() {return magnitude;} 
double getAngle() {return angle;} 

// Mutators 
void setRectangular(double re, double im) 
{ 
    real = re; 
    imaginary = im; 
    magnitude = rectangularToMagnitude(re, im); 
    angle = rectangularToAngle(re, im); 
} 

void setPolar(double ma, double an) 
{ 
    real = polarToReal(ma, an); 
    imaginary = polarToImaginary(ma, an); 
    magnitude = ma; 
    angle = an; 
} 

錯誤

error C2065: 'real' : undeclared identifier 
error C2065: 'imaginary' : undeclared identifier 
error C2065: 'magnitude' : undeclared identifier 
error C2065: 'angle' : undeclared identifier 
error C2065: 'real' : undeclared identifier 
error C2065: 'imaginary' : undeclared identifier 
error C2065: 'magnitude' : undeclared identifier 
error C3861: 'rectangularToMagnitude': identifier not found 
error C2065: 'angle' : undeclared identifier 
error C3861: 'rectangularToAngle': identifier not found 
error C2065: 'real' : undeclared identifier 
error C3861: 'polarToReal': identifier not found 
error C2065: 'imaginary' : undeclared identifier 
error C3861: 'polarToImaginary': identifier not found 
error C2065: 'magnitude' : undeclared identifier 
error C2065: 'angle' : undeclared identifier 
IntelliSense: identifier "real" is undefined 
IntelliSense: identifier "imaginary" is undefined 
IntelliSense: identifier "magnitude" is undefined 
IntelliSense: identifier "angle" is undefined 
IntelliSense: identifier "real" is undefined 
IntelliSense: identifier "imaginary" is undefined 
IntelliSense: identifier "magnitude" is undefined 
IntelliSense: identifier "rectangularToMagnitude" is undefined 
IntelliSense: identifier "angle" is undefined 
IntelliSense: identifier "rectangularToAngle" is undefined 
IntelliSense: identifier "real" is undefined 
IntelliSense: identifier "polarToReal" is undefined 
IntelliSense: identifier "imaginary" is undefined 
IntelliSense: identifier "polarToImaginary" is undefined 
IntelliSense: identifier "magnitude" is undefined 
IntelliSense: identifier "angle" is undefined 
+0

您能否將您遇到的錯誤添加到您的問題中? – 2012-04-19 12:45:53

+0

我有26個未聲明的標識符錯誤,其中頭文件中聲明的變量未被標識。該文件第一次建立(與男生錯誤),但改變文件後,它不是建立了。 – 2012-04-19 12:47:53

+0

確保將標題添加到您正在構建的項目中。 – 2012-04-19 12:48:20

回答

3

您需要定義,例如,getReal()爲複雜:: getReal()在你的.cpp文件中。另外,getReal()之後的所有成員函數都是這種情況。

+0

太棒了,我站出來了,這是我的錯!非常感謝。 – 2012-04-19 13:33:06

+0

這很難找到。但對於第一次看到代碼的人來說可能更容易。 – 2012-04-19 13:37:24