473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1657
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.