friend problem in GCC 3.3.1

R

Ryan Liu

Hi all,

Can I define friend class in another class.
I know in Sun CC envionment, it is ok.
for example:

Class A:..
{
...
friend ClassName;
...
}
But this usage is not right in GCC.
Would you mind giving some suggestion?

Thanks you in advance.
Ryan
 
M

Mike Wahler

Ryan Liu said:
Hi all,

Can I define friend class in another class.
I know in Sun CC envionment, it is ok.
for example:

Class A:..

class A
{
...
friend ClassName;
...
}
But this usage is not right in GCC.
Would you mind giving some suggestion?

You'll need to provide a complete program example of what
"doesn't work".

I.e. the above should be OK (once the syntax errors are fixed)
if the symbol 'ClassName' is known at the point where you define class 'A'.

class ClassName;
class A
{
friend ClassName;
};

If this won't compile, your compiler is broken.

(Of course if you want to actually instantiate a type 'ClassName'
object, or refer to any of its members, the full class definition must
be in scope).

-Mike
 
A

Alf P. Steinbach

* "Mike Wahler said:
class ClassName;
class A
{
friend ClassName;
};

If this won't compile, your compiler is broken.

That turns out not to be the case.

The Holy Standard (you know ;-) ) requires one of the words "class"
or "struct" here, IIRC an "elaborated specifier".

So, more correct: if the above compiles, then the compiler is a bit
broken -- not much, but a little.
 
M

Mike Wahler

Alf P. Steinbach said:
That turns out not to be the case.

The Holy Standard (you know ;-) ) requires one of the words "class"
or "struct" here, IIRC an "elaborated specifier".

So, more correct: if the above compiles, then the compiler is a bit
broken -- not much, but a little.

I suspected something "wasn't quite right", compounded by the fact
the the implementation I tested with does indeed seem to be a
"little" broken. Thanks for clearing that up.

-Mike
 
M

Mike Wahler

Mike Wahler said:
"Alf P. Steinbach" <[email protected]> wrote in message

BTW Alf, over at comp.os.ms-windows.programmer.win32, I posted a question
in response to one of your posts, but nobody replied. Message ID is:
(It was sometime around beginning of February).

If you have a spare minute or two ...

-Mike
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top