problem in declaration

D

David Lindauer

If I do this:

struct xyz
{
xyz();
int a,b;
} var1;

it compiles.

But if I do this

struct xyz
{
xyz();
int a,b;
} var2();

it doesn't compile. The comeau compiler says var2() is a function
rather than a variable initialization...

but then I can do this:

struct xyz
{
xyz();
int a,b;
} ;
struct xyz var3();

and that compiles.

What is the rational for the difference in behavior?

Thanks,

David
 
V

Victor Bazarov

David said:
If I do this:

struct xyz
{
xyz();
int a,b;
} var1;

it compiles.

But if I do this

struct xyz
{
xyz();
int a,b;
} var2();

it doesn't compile. The comeau compiler says var2() is a function
rather than a variable initialization...

Yes, it is.
but then I can do this:

struct xyz
{
xyz();
int a,b;
} ;
struct xyz var3();

and that compiles.

What is the rational for the difference in behavior?

Types are not allowed to be _defined_ in a function declaration.

V
 
R

Rolf Magnus

David said:
If I do this:

struct xyz
{
xyz();
int a,b;
} var1;

it compiles.

But if I do this

struct xyz
{
xyz();
int a,b;
} var2();

it doesn't compile. The comeau compiler says var2() is a function
rather than a variable initialization...

but then I can do this:

struct xyz
{
xyz();
int a,b;
} ;
struct xyz var3();

and that compiles.

What is the rational for the difference in behavior?

If it looks like a function declaration, it is a function declaration.
Your second example is similar to:

type name();

which clearly looks like a function declaration.
 

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,801
Messages
2,569,659
Members
45,427
Latest member
Fredrick95

Latest Threads

Top