471,089 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

error passing array of abstract type

Hello,

I have run into a problem with VC7 that worked in VC6.

These two sections should be exactly the same...

class test { public: virtual void blah(void)=0;};
void func(test[]) {}

and

class test { public: virtual void blah(void)=0;};
void func(test const *) {}

but only the 2nd compiles in VC7 where as both compiled in VC6.
The VC7 error for the first one is error C2259: 'test' : cannot instantiate
abstract class

Any reason why VC7 doesn't accept it?

Thanks
Nov 16 '05 #1
4 1572
Andrew K wrote:
Hello,

I have run into a problem with VC7 that worked in VC6.

These two sections should be exactly the same...

class test { public: virtual void blah(void)=0;};
void func(test[]) {}

and

class test { public: virtual void blah(void)=0;};
void func(test const *) {}

but only the 2nd compiles in VC7 where as both compiled in VC6.
The VC7 error for the first one is error C2259: 'test' : cannot
instantiate abstract class

Any reason why VC7 doesn't accept it?


Yes, because it's illegal. It's not possible to create an array of 'test'
since it contains a pure virtual function. VC6 was wrong to accept it.

-cd
Nov 16 '05 #2
But 'test[]' is the same as 'test const *' isn't it? Pointers to abstract
classes are legal so if the two are equivalent then the array version should
be accepted to no?

I'm missing something aren't I?

"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Andrew K wrote:
Hello,

I have run into a problem with VC7 that worked in VC6.

These two sections should be exactly the same...

class test { public: virtual void blah(void)=0;};
void func(test[]) {}

and

class test { public: virtual void blah(void)=0;};
void func(test const *) {}

but only the 2nd compiles in VC7 where as both compiled in VC6.
The VC7 error for the first one is error C2259: 'test' : cannot
instantiate abstract class

Any reason why VC7 doesn't accept it?


Yes, because it's illegal. It's not possible to create an array of 'test'
since it contains a pure virtual function. VC6 was wrong to accept it.

-cd

Nov 16 '05 #3
I thought VC7 was correct initially too, but then read some google postings
that said the two versions I showed should be equivalent, but it was in the
context of a char(which should make no different I'd think). I also tried
it in gcc and it accepted both versions, which was why I asked.

Thanks

"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Andrew K wrote:
Hello,

I have run into a problem with VC7 that worked in VC6.

These two sections should be exactly the same...

class test { public: virtual void blah(void)=0;};
void func(test[]) {}

and

class test { public: virtual void blah(void)=0;};
void func(test const *) {}

but only the 2nd compiles in VC7 where as both compiled in VC6.
The VC7 error for the first one is error C2259: 'test' : cannot
instantiate abstract class

Any reason why VC7 doesn't accept it?


Yes, because it's illegal. It's not possible to create an array of 'test'
since it contains a pure virtual function. VC6 was wrong to accept it.

-cd

Nov 16 '05 #4
Andrew K wrote:
I thought VC7 was correct initially too, but then read some google
postings that said the two versions I showed should be equivalent,
but it was in the context of a char(which should make no different
I'd think). I also tried it in gcc and it accepted both versions,
which was why I asked.


The C++ standard is actually quite specific on it. Section 8.3.4, paragraph
1 says:

<quote>
In a declaration T D where D has the form
D1 [constant-expression-opt]

and the type of the identifier in the declaration T D1 is
"derived-declarator-type-list T," then the type of the
identifier of D is an array type. T is called the array element type; this
type shall not be a reference type, the
(possibly cv-qualified) type void, a function type or an abstract class
type. ...
</quote>

VC7 and 7.1 are correct in rejecting it. In the cases where it's legal, the
two parameter lists that you showed are effectively identical - the array
syntax is simply not legal for abstract classes.

-cd
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Eric A. Forgy | last post: by
4 posts views Thread by ron | last post: by
33 posts views Thread by Martin Jørgensen | last post: by
669 posts views Thread by Xah Lee | last post: by
Dormilich
2 posts views Thread by Dormilich | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.