Cannot compile .cc with Sun Workshop C++ 5.3

Discussion in 'C++' started by Laax, Oct 1, 2003.

  1. Laax

    Laax Guest

    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.
     
    Laax, Oct 1, 2003
    #1
    1. Advertising

  2. Laax

    Mike Wahler Guest

    "Laax" <> wrote in message
    news:...
    > 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 <iostream> (no .h)

    >
    > 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
     
    Mike Wahler, Oct 1, 2003
    #2
    1. Advertising

  3. Laax

    Laax Guest

    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.
     
    Laax, Oct 2, 2003
    #3
  4. Laax

    Mike Wahler Guest

    "Laax" <> wrote in message
    news:...
    > 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.
    >
    > ----------
    > ACString.h
    > ----------
    > ...
    > ...
    > #include <iostream.h>


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

    > #include <ACTypes.h>
    >
    > class ACString
    > {
    > ...
    > ...
    > friend ostream& operator << ( ostream& os, const ACString &rhs );
    > ...
    > ...
    > }


    You're missing a semicolon here.

    };

    >
    > --------
    > Sample.h
    > --------
    > ...
    > ...
    > #include <ACString.h>
    > ...
    > ...
    > ----------------------------------------------
    >
    > Now, what is the problem in this code?


    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
     
    Mike Wahler, Oct 2, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Cham
    Replies:
    0
    Views:
    379
    James Cham
    Jul 21, 2003
  2. Replies:
    0
    Views:
    2,909
  3. Dain Reinhart
    Replies:
    1
    Views:
    960
    Thomas Matthews
    Jan 29, 2004
  4. Nagaraj
    Replies:
    1
    Views:
    900
    Lionel B
    Mar 1, 2007
  5. Schneider, Michael

    SUN 1.8.0 Build Patches - SUN Workshop 6.1

    Schneider, Michael, Aug 25, 2003, in forum: Ruby
    Replies:
    0
    Views:
    109
    Schneider, Michael
    Aug 25, 2003
Loading...

Share This Page