错误C2146和C4430

时间:2011-07-31 03:32:35

标签: windows

首先:抱歉我的英语不好=((

Sencond:

这是我在“Global.h”中的代码:

#pragma once
class GlobalVariable
{
public:
    GlobalVariable(void);
    ~GlobalVariable(void);

    //------------------------------------------------
public:
    double pixelWidth;      //  do rong cua 1 pixel tren Viewport
    double pixelHeigh;      //  do cao cua 1 pixel tren Viewport

public:
    Point   oldPoint,   tempPoint;
    Circle  oldCir,     tempCir;
    DaGiac  oldDaGiac,  tempDaGiac;
    Color   oldObjColor,tempObjColor, OxyColor;

};

class Point
{
public:
    Point(void);
    ~Point(void);

    double  x,y;            // toạ độ (x,y)
};

class Color
{
public:
    Color(void);
    ~Color(void);

    double R,G,B;           // màu (R,G,B)
};

class DaGiac
{
public:
    DaGiac(void);
    ~DaGiac(void);

    int numOfPeak;  //so' dinh?
    Point peakArr[10];  //  ve da giac canh so dinh toi da la 10
};

class Circle
{
public:
    Circle(void);
    ~Circle(void);

    Point centre;
    double radius;

};


我有些感慨:(

------ Build started: Project: GAS, Configuration: Debug Win32 ------
Compiling...
GlobalVariable.cpp
e:\documents\bin\gas_project\globalvariable.h(15) : error C2146: syntax error : missing ';' before identifier 'oldPoint'
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C2146: syntax error : missing ';' before identifier 'oldCir'
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C2146: syntax error : missing ';' before identifier 'oldDaGiac'
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C2146: syntax error : missing ';' before identifier 'oldObjColor'
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Build log was saved at "file://e:\Documents\BIN\GAS_Project\Debug\BuildLog.htm"
GAS - 17 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

但是在删除GlobalVariable类之后!只有Class Point,Color,DaGiac,Circle存在!它没有恐怖! 告诉我为什么?以及如何核心该错误?请=((

1 个答案:

答案 0 :(得分:2)

编译器无法“看到”其他类,因为它们是在 GlobalVariable类之后定义的。将整个GlobalVariable类移动到文件的底部,以便在需要时定义它所依赖的所有类。