472,958 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1636
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eric A. Forgy | last post by:
Hello, I am just learning Java and am trying to write a method that does something like //=========================================== public Static List find(double array,double val,String...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
4
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
33
by: Martin Jørgensen | last post by:
Hi, In continuation of the thread I made "perhaps a stack problem? Long calculations - strange error?", I think I now got a "stable" error, meaning that the error always seem to come here now...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
2
Dormilich
by: Dormilich | last post by:
Hi, I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means: Error: Fatal error: Can't use method return value in write context in "output.php" on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.