c++ - Visual Studio 2010 不构建 header 更新

标签 c++ visual-studio-2010 header-files

我正在使用带有 C++ 的 Visual Studio 2010,尽管将预编译 header 选项设置为“不使用预编译 header ”,它仍然坚持忽略我的 header 。在另一台机器上,它使用相同的设置工作正常。我该如何解决这个问题?

复杂.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);
};

复杂.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

最佳答案

例如,您需要在 .cpp 文件中将 getReal() 定义为 Complex::getReal()。此外,getReal() 之后的所有成员函数都是这种情况。

关于c++ - Visual Studio 2010 不构建 header 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10228314/

相关文章:

visual-studio-2010 - Visual Studios 2010-Asp.net MVC 4 Beta-粘贴的长时间延迟和频繁崩溃

vb.net - 在 DataGridView 中获取 "current cell"的 X/Y 坐标?

c++ - STL 容器的转发 header

C++ - 导出 C++ 库公共(public)部分的正确方法

c++ - 为什么 link_libraries(stdc++fs) 有效但 -lstdc++fs 无效?

c++ - 在 std::map 中存储 boost::bind 函数

c++ - 库会覆盖信号处理程序,但我需要按 CTRL+C 进行清理

c++ - 为什么同一编译器的不同版本会给出不同的结果?

c++ - 将 "normal"std::string 转换为 utf-8

ios - 如何在 iOS 的头文件中创建 CGSize 类型的常量?