a compliation error

M

multics.cn

Dear all,
I have one line in my cpp source file.

void (**fa)(char,float) = new (void [](char,float));

I tried gcc and vc express, both result in compliation error:

g++ gives:
error: creating array of functions

vc express gives:
error C2092: 'abstract declarator' array element type cannot be
function

Can any one help on the error information?

Thanks
 
I

Ian Collins

multics.cn said:
Dear all,
I have one line in my cpp source file.

void (**fa)(char,float) = new (void [](char,float));

I tried gcc and vc express, both result in compliation error:

g++ gives:
error: creating array of functions

Can any one help on the error information?
What are you trying to do?
 
A

Alf P. Steinbach

* multics.cn:
Dear all,
I have one line in my cpp source file.

void (**fa)(char,float) = new (void [](char,float));

I tried gcc and vc express, both result in compliation error:

g++ gives:
error: creating array of functions

vc express gives:
error C2092: 'abstract declarator' array element type cannot be
function

Can any one help on the error information?

Try

typedef void (*PMyFunc)(char, float);

std::vector<PMyFunc> fa;

Cheers, & hth.,

- Alf
 
K

Kai-Uwe Bux

multics.cn said:
Dear all,
I have one line in my cpp source file.

void (**fa)(char,float) = new (void [](char,float));

You should take that apart using typedefs:

typedef void (*function_ptr)( char, float );
typedef function_ptr* function_ptr_ptr;

Then, you can allocate:

function_ptr_ptr fa = new function_ptr [10];

I tried gcc and vc express, both result in compliation error:

g++ gives:
error: creating array of functions

vc express gives:
error C2092: 'abstract declarator' array element type cannot be
function

Can any one help on the error information?

You have a type-mismatch because you put too much on one line. The left hand
is a pointer-to-pointer-to-function. The expression in the new-clause is

void [] ( char, float );

and I don't even know whether that is legal (it would be an
array-of-function).


What is it that you are trying to do?


Best

Kai-Uwe Bux
 
M

multics.cn

...
and I don't even know whether that is legal (it would be an
array-of-function).

What is it that you are trying to do?

Thi is illegal based on the compliation error, and I was curiousing
why it is illegal.
 
K

Kai-Uwe Bux

multics.cn said:
Thi is illegal based on the compliation error, and I was curiousing
why it is illegal.

As usual: because the standard says so [8.3.4/1]:

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.


Best

Kai-Uwe Bux
 
M

multics.cn

Thi is illegal based on the compliation error, and I was curiousing
why it is illegal.

As usual: because the standard says so [8.3.4/1]:

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.

After changing to
void (**fa)(char,float) = new (void (*[])(char,float));
the problem is resolved.

Thanks for your information anyway.
 
J

James Kanze

I have one line in my cpp source file.
void (**fa)(char,float) = new (void [](char,float));
I tried gcc and vc express, both result in compliation error:
g++ gives:
error: creating array of functions
vc express gives:
error C2092: 'abstract declarator' array element type cannot be
function
Can any one help on the error information?

The error messages seem pretty clear to me. "void
[](char,float)" has the type "array of function...", and you
can't have an array of functions. Given the declaration on the
left, you probably want "void (*[n])(char,float)", and array of
pointers to functions. And you'll have to specify the size of
the array in a new expression, of course. Whence the n.

Much better, of course, would be to use vector:

std::vector< void(*)( char, float ) > v ;
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top