我收到错误“C2143:语法错误:缺少';' 在 Track.h 中的 '*' 之前,我相信这是由于“缺少”类定义。
这些是3个头文件:
Topics.h,包级头文件,#include 其他所有内容:
#ifndef Topics_H
#define Topics_H
#include <oxf\oxf.h>
#include "Request.h"
#include "TDPoint.h"
#include "Track.h"
#include "TrackReport.h"
#endif
然后是 TDPoint(如“3DPoint”),它简单地定义了一个具有 3 个长属性的类:
#ifndef TDPoint_H
#define TDPoint_H
#include <oxf\oxf.h> // Just IBM Rational Rhapsody's Framework
#include "Topics.h"
class TDPoint {
//// Constructors and destructors ////
public :
TDPoint();
~TDPoint();
//// Additional operations ////
long getX() const;
void setX(long p_x);
long getY() const;
void setY(long p_y);
long getZ() const;
void setZ(long p_z);
//// Attributes ////
protected :
long x;
long y;
long z;};
#endif
但问题出在这里,在标记的行中:
#ifndef Track_H
#define Track_H
#include <oxf\oxf.h> // Just IBM Rational Rhapsody's Framework
#include "Topics.h"
#include "TDPoint.h"
class Track {
public :
//// Operations ////
std::string getId() const;
void setId(std::string p_id);
TDPoint* getPosition() const; // <--- This line, the first line to use TDPoint, throws the error
//// Attributes ////
protected :
std::string id;
TDPoint position;
public :
Track();
~Track();
};
#endif
我的猜测是编译器(MS VS2008/MSVC9)根本不知道“TDPoint”类。但即使在与“Track”相同的头文件中定义类,或者使用像“class TDPoint”这样的前向声明(然后抛出错误:未定义的类)也无济于事。代码是从 Rhapsody 自动生成的,如果这有什么不同的话。
但也许这个错误完全是另一回事?