由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - What is wrong in this array declaration.
相关主题
Question about a C++ compilation error on Visual Studio 2005问个虚函数的作用
question for C++ constant一个C++语法问题
C++ 的 问题how do I reseat a reference?
int *a [] 和int (*a)[] 一样吗C++ syntax question
关于C++ STL编译的疑问question about c++ constructor
class D:public B;private destructor
C++ memcpy declaration use restrict keyword?请问这个C++程序有什么问题吗
[合集] 编程的习惯问题【求助】为什么类里面不能初始化vector的大小? (转载)
相关话题的讨论汇总
话题: circle话题: shape话题: error话题: what话题: new
进入Programming版参与讨论
1 (共1页)
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'?
1 (共1页)
进入Programming版参与讨论
相关主题
【求助】为什么类里面不能初始化vector的大小? (转载)关于C++ STL编译的疑问
Question about friend in C++class D:public B;
A C++ QuestionC++ memcpy declaration use restrict keyword?
请教有关header file的几个问题[合集] 编程的习惯问题
Question about a C++ compilation error on Visual Studio 2005问个虚函数的作用
question for C++ constant一个C++语法问题
C++ 的 问题how do I reseat a reference?
int *a [] 和int (*a)[] 一样吗C++ syntax question
相关话题的讨论汇总
话题: circle话题: shape话题: error话题: what话题: new