为什么以下的C++ code有compile error?
所在版块:技术の宅 发贴时间:2006-12-16 09:30

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
Test_Class.cpp
==============================
class CRectangle{
int *width, *height;
public:
CRectangle (int a, int b){
width= new int;
height = new int;
*width = a;
*height = b;
}
~CRectangle(){
delete width;
delete height;
}
int area(){
return ((*width)*(*height));
}
};
=================================

Do_Factorial.cpp


=================================
#include<iostream>

class CRectangle;

int main()
{
CRectangle c(2,3);
std::cout<<c.area()<<'\n';
}
=================================

compile error 是:

g++ do_factorial.cpp test_class.cpp -o do_factorial

do_factorial.cpp: In function `int main()':
do_factorial.cpp:9: variable `CRectangle c' has initializer but incomplete type
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

 相关帖子 我要回复↙ ↗回到正文
为什么以下的C++ code有compile error? Yahoo!   (916 bytes , 747reads )
java用多了吧 hula   (191 bytes , 342reads )
haha, java syndrome sarah   (0 bytes , 222reads )