syntax error

A

Andy White

template <class Type>
class Array
{
public:
explicit Array(int size = DefaultArraySize);
Array(Type *array, int array_size);
Array(const Array &rhs);

virtual ~Array() {delete [] ia;}

bool operator==(const Array &) const;
bool operator!=(const Array &) const;

virtual Type &operator[](int index) {return ia[index];}
virtual void sort();

virtual Type min() const;
virtual Type max() const;
virtual int find(const Type &value) const;

protected:
static const int DefaultArraySize = 12; // <----- problem, compiler says
illegal pure syntax, must be 0.
// Why wont my
compiler let this go?
//My book says
this is ok as long as it's "static const int".

int _size;
Type *ia;
};
 
V

Victor Bazarov

Andy said:
template <class Type>
class Array
{
public:
explicit Array(int size = DefaultArraySize);
Array(Type *array, int array_size);
Array(const Array &rhs);

virtual ~Array() {delete [] ia;}

bool operator==(const Array &) const;
bool operator!=(const Array &) const;

virtual Type &operator[](int index) {return ia[index];}
virtual void sort();

virtual Type min() const;
virtual Type max() const;
virtual int find(const Type &value) const;

protected:
static const int DefaultArraySize = 12; // <----- problem, compiler says
illegal pure syntax, must be 0.
// Why wont my
compiler let this go?
//My book says
this is ok as long as it's "static const int".

int _size;
Type *ia;
};

Apparently your compiler is old and non-compliant.

V
 
A

Andy White

Victor Bazarov said:
Andy said:
template <class Type>
class Array
{
public:
explicit Array(int size = DefaultArraySize);
Array(Type *array, int array_size);
Array(const Array &rhs);

virtual ~Array() {delete [] ia;}

bool operator==(const Array &) const;
bool operator!=(const Array &) const;

virtual Type &operator[](int index) {return ia[index];}
virtual void sort();

virtual Type min() const;
virtual Type max() const;
virtual int find(const Type &value) const;

protected:
static const int DefaultArraySize = 12; // <----- problem, compiler says
illegal pure syntax, must be 0.
// Why wont my
compiler let this go?
//My book says
this is ok as long as it's "static const int".

int _size;
Type *ia;
};

Apparently your compiler is old and non-compliant.

V

I have vc++ 6.0, I haven't bothered looking into the most up to date
version, what would that be?
 
V

Victor Bazarov

Andy said:
Victor Bazarov said:
[...]
Apparently your compiler is old and non-compliant.

V


I have vc++ 6.0, I haven't bothered looking into the most up to date
version, what would that be?

Current release is .NET (or "2003"), which is 7.1 (compiler v 13.1) and
2005, or v8 (compiler v14), is in Beta, last time I looked. The 7.1 is
miles ahead of 6.0, although not free from its quirks.

V
 
L

Larry I Smith

Andy said:
Victor Bazarov said:
Andy said:
template <class Type>
class Array
{
public:
explicit Array(int size = DefaultArraySize);
Array(Type *array, int array_size);
Array(const Array &rhs);

virtual ~Array() {delete [] ia;}

bool operator==(const Array &) const;
bool operator!=(const Array &) const;

virtual Type &operator[](int index) {return ia[index];}
virtual void sort();

virtual Type min() const;
virtual Type max() const;
virtual int find(const Type &value) const;

protected:
static const int DefaultArraySize = 12; // <----- problem, compiler says
illegal pure syntax, must be 0.
// Why wont my
compiler let this go?
//My book says
this is ok as long as it's "static const int".

int _size;
Type *ia;
};
Apparently your compiler is old and non-compliant.

V

I have vc++ 6.0, I haven't bothered looking into the most up to date
version, what would that be?

Try this free download:

http://lab.msdn.microsoft.com/express/visualc/default.aspx

Regards,
Larry
 
R

red floyd

Andy said:
[redacted]
I have vc++ 6.0, I haven't bothered looking into the most up to date
version, what would that be?

As Victor said, 7.1 (VS.NET 2003) is much better. It's about 98/99%
standards compliant. Also, in addition to the sort of construct you had
there, VC6 is notoriously bad with template code.

I'd highly recommend either 7.1 or a MinGW g++ variant for Windows
programming.
 
R

Richard Herring

Andy White said:
template <class Type>
class Array
{
public:
explicit Array(int size = DefaultArraySize);
Array(Type *array, int array_size);
Array(const Array &rhs);

virtual ~Array() {delete [] ia;}

Not that this answers your question, but you'd better declare a copy
assignment operator to make the third in the "rule of three".
bool operator==(const Array &) const;
bool operator!=(const Array &) const;

virtual Type &operator[](int index) {return ia[index];}
virtual void sort();

virtual Type min() const;
virtual Type max() const;
virtual int find(const Type &value) const;

protected:
static const int DefaultArraySize = 12; // <----- problem, compiler says
illegal pure syntax, must be 0.
// Why wont my
compiler let this go?
//My book says
this is ok as long as it's "static const int".

int _size;
Type *ia;
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top