Redian新闻
>
What is wrong in this array declaration.
avatar
What is wrong in this array declaration.# Programming - 葵花宝典
t*a
1
aha是一个,还有呢?
比如对应哈哈的,对应呵呵的,对应嘿嘿的,对应hoho的。。。
avatar
n*d
2
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
avatar
r*r
4
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.
avatar
k*f
5
Nothing is wrong.
Compiles fine with g++ and VC++2008. Did you have a typo somewhere?
avatar
O*y
6
I am not able to duplicate your syntax errors either. But you need release
the memory since you "new" three Circle objects.
avatar
n*d
7
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?

avatar
k*f
8
vc6古董了,换个新的

【在 n**d 的大作中提到】
: You are right. I tried the same code by g++, no error.
: But VC++ 6.0 gives this error.

avatar
K*n
9
change
Shape* sarray[] = {new Circle, new Circle, new Circle};
to
Shape* sarray[] = {new Circle(), new Circle(), new Circle()};
VC++ 6.0 compiles without errors.
avatar
l*a
10
g++ no problem;
Mac OS 10.5 eclipse c++;
btw: why dont have a delete for your 'new'?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。