Cannot compile .cc with Sun Workshop C++ 5.3

L

Laax

Hi,

I am trying to compile a .cc file and get the following error.
I have translated the error message from original japanese text. So,
it may not look exactly like standard(English) error message.

Errors:
1. Warning (an old function) : specific "class" is necessary by
friend designation toward the class.
2. Found & where , is expected.

The source code on that particular line is:
extern "C" {
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
}
#include <iostream.h>

friend ostream& operator<<( ostream& os, const ACString &rhs );

CC Version:
CC: Sun WorkShop 6 update 2 C++ 5.3 2001/05/15

Compiler Flags used:
-KPIC -compat=4 -mt -pta

What is the problem? How do I fix it?

Thanks.

Laax.
 
M

Mike Wahler

Laax said:
Hi,

I am trying to compile a .cc file and get the following error.
I have translated the error message from original japanese text. So,
it may not look exactly like standard(English) error message.

Errors:
1. Warning (an old function) : specific "class" is necessary by
friend designation toward the class.
2. Found & where , is expected.

The source code on that particular line is:
extern "C" {
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
}
#include <iostream.h>

This is not a standard C++ header. The header which
declares the standard streams is said:
friend ostream& operator<<( ostream& os, const ACString &rhs );

A friend declaration must be inside a class body.
This is simply not valid C++. The message about the
'&' is an artifact of the first -- friend needs to
be inside a class. Outside a class, it is not
meaningful. Do you know what the keyword 'friend'
means?

CC Version:
CC: Sun WorkShop 6 update 2 C++ 5.3 2001/05/15

Compiler Flags used:
-KPIC -compat=4 -mt -pta

C++ is a platform-independent language, it should not
matter which implemenation you use.
What is the problem?

You're trying to compile invalid code.
How do I fix it?

Write valid code. You also failed to provide a
definition for type 'ACString'.

-Mike
 
L

Laax

Hi Mike,

Thanks for your mail.

I am using ACString class in, say Sample.h. I am able to come
ACString class but not Sample. I get the mentioned errors, targeting
the friend function declartion in ACString.h. Both these classes are
in different module.

I didn't give the complete code...Actually the friend function
declation in ACString.h, is inside the class definition. let me give
you clear picture.

----------
ACString.h
----------
....
....
#include <iostream.h>
#include <ACTypes.h>

class ACString
{
....
....
friend ostream& operator << ( ostream& os, const ACString &rhs );
....
....
}

--------
Sample.h
--------
....
....
#include <ACString.h>
....
....
----------------------------------------------

Now, what is the problem in this code? Should I use namespace?
and Should I use any particular compiler option to compile such a
code?

Laax.
 
M

Mike Wahler

Laax said:
Hi Mike,

Thanks for your mail.

I am using ACString class in, say Sample.h. I am able to come
ACString class but not Sample. I get the mentioned errors, targeting
the friend function declartion in ACString.h. Both these classes are
in different module.

I didn't give the complete code...

And you still didn't here.
Actually the friend function
declation in ACString.h, is inside the class definition. let me give
you clear picture.

There is no such header in standard C++. THe header
which declares the standard stream objects (e.g. 'std::cout')
is said:
#include <ACTypes.h>

class ACString
{
...
...
friend ostream& operator << ( ostream& os, const ACString &rhs );
...
...
}

You're missing a semicolon here.

};
--------
Sample.h
--------
...
...
#include <ACString.h>
...
...

I cannot say, since you only provided bits and pieces of it.
And I won't guess.
Should I use namespace?

nor should you.
and Should I use any particular compiler option to compile such a
code?

Compiler options are specific to each compiler, all
are not the same. This is why we don't discuss them
here, only the language itself.

Put together a *complete* example of the code you feel
should compile successfully. If the code depends upon
any non standard headers, such as "ACTypes.h" and
"ACString.h", you need to show those files too.
Try to pare things down to the smallest amount
possible that still shows the problem. That way
we won't have to wade through a lot of code to
find the trouble (also many folks here won't even
look at code more than a few dozen lines). In the
process of creating this example code, often you'll
spot the problem yourself.

-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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top