C++ 在C+;中创建头文件时出错+;

C++ 在C+;中创建头文件时出错+;,c++,oop,header-files,C++,Oop,Header Files,文件Rectangle.hxx中有一个头文件 #ifndef Rectangle_included #define Rectangle_included #include <iostream> #include <math.h> #include "GetL.hxx" using namespace std; class Rectangle: public GetL { int width; int value; public: Rectangle(); Rectang

文件Rectangle.hxx中有一个头文件

#ifndef Rectangle_included
#define Rectangle_included
#include <iostream>
#include <math.h>
#include "GetL.hxx"
using namespace std;

class Rectangle: public GetL
{
int width;
int value;
public:
Rectangle();
Rectangle(int v, int w);
Rectangle(const Rectangle& b);
int getWidth();
int getValue();
Rectangle & plus(int newval);
};
#endif //Rectangle_included

我怎样才能删除它?我如何定义文件GetL.cxx或者我不需要这样做?

您需要编译不同的文件,而无需先链接。在UNIX编译器上,这通常使用
-c
选项完成。在构建可执行文件时,指定所有生成的
.o
对象。或者,您可以一次指定所有源文件,但这实际上只适用于非常小的项目。

您必须实现
GetL::getWidth()
。考虑到您的其他文件,您可能会在
GetL.cxx

中实现它。您能告诉我如何实现吗?我在Windows上使用cygwin,只需使用
g++-c Rectangle.cxx
和其他源文件。最后,将所有文件放在一起:
g++-o program.exe Rectangle.o GetL.o main.o
(我不知道gcc在使用cygwin时是否生成
.o
文件或
.obj
:这可能需要更改)。为了减少痛苦,您应该阅读
make
(或
gmake
)并使用
Makefile
。请告诉我们您用于构建程序的命令,该命令会导致您发布错误消息。另外,您是否编写了GetL.cxx?如果是,请给我们看看。另外,您没有
int main()
@Rob我在cygwin工作,使用命令
g++Rectangle.cxx
,我到目前为止还没有编写GetL.cxx和main()。@Rob我在问题的第二部分询问了GetL.cxx,但我在Rectangle.cxx中实现了这个函数。我在Rectangle.cxx中看到了
Rectangle::getWidth
,但是我没有看到
GetL::getWidth
。您还必须实现
GetL::getWidth
#ifndef GetL_included
#define GetL_included
#include <iostream>
using namespace std;
class GetL
{
public:
virtual int getWidth();
};
#endif //GetL_include
#include <iostream>
#include <math.h>
#include "Rectangle.hxx"
using namespace std;

Rectangle::Rectangle()
{
 value=0;
 width=0;
}
Rectangle::Rectangle(int v, int w)
{
 value=v;
 width=w;
}
Rectangle::Rectangle(const Rectangle& b)
{
 value= b.value;
 width= b.width;
}
int Rectangle::getWidth()
{
 return width;
}
int Rectangle::getValue()
{
  return value;
}
Rectangle& Rectangle::plus(int newval)
{
  value+=newval;
  if(value>=pow(2,width))
cout<<"Overflow";
  return *this;
}
/tmp/cclETn3R.o:Rectangle.cxx:(.text$_ZN4GetLC2Ev[GetL::GetL()]+0*8): undefined reference to 'vtable for Getl'