n**d 发帖数: 9764 | 1 Shape* sarray[] = {new Circle, new Circle, new Circle};
error C2143: syntax error : missing ';' before '}'
error C2059: syntax error : ';'
The following is the full code.
#include
class Shape {
public:
virtual void draw() = 0;
virtual void erase() = 0;
virtual ~Shape() {}
};
class Circle : public Shape {
public:
Circle() {}
~Circle() { std::cout << "Circle::~Circle\n"; }
void draw() { std::cout << "Circle::draw\n";}
void erase() { std::cout << "Circle::eras |
r*********r 发帖数: 3195 | 2 r u sure? i don't see anything wrong with the code,
other than there shouldn't be a semicolon after main, but it's no biggie. |
k**f 发帖数: 372 | 3 Nothing is wrong.
Compiles fine with g++ and VC++2008. Did you have a typo somewhere? |
O*********y 发帖数: 633 | 4 I am not able to duplicate your syntax errors either. But you need release
the memory since you "new" three Circle objects. |
n**d 发帖数: 9764 | 5 You are right. I tried the same code by g++, no error.
But VC++ 6.0 gives this error.
【在 k**f 的大作中提到】 : Nothing is wrong. : Compiles fine with g++ and VC++2008. Did you have a typo somewhere?
|
k****f 发帖数: 3794 | 6 vc6古董了,换个新的
【在 n**d 的大作中提到】 : You are right. I tried the same code by g++, no error. : But VC++ 6.0 gives this error.
|
K*****n 发帖数: 65 | 7 change
Shape* sarray[] = {new Circle, new Circle, new Circle};
to
Shape* sarray[] = {new Circle(), new Circle(), new Circle()};
VC++ 6.0 compiles without errors. |
l**a 发帖数: 423 | 8 g++ no problem;
Mac OS 10.5 eclipse c++;
btw: why dont have a delete for your 'new'? |