This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ language lawyer question


In the process of compiling KDE 3.2 on IRIX 6.5 and Tru64 UNIX 5.1
with the respective vendor C++ compilers, I ran into a namespace
issue. Consider the following:

$ cat a.h
class KMAcctImap;

namespace KIO {
  class Job {
  public:
    int b;
  };
}

namespace KMail {
  class ImapJob {
    friend class KMAcctImap;
  public:
    ImapJob();

  private:
    KIO::Job *mJob;
  };
}

$ cat b.cpp
namespace KIO {
  class Job;
}
namespace KMail {
  class ImapJob;
}
using KMail::ImapJob;

class KMAcctImap
{
  friend class KMail::ImapJob;

public:
  void test (void);
};

#include "a.h"

void KMAcctImap::test (void) {
  ImapJob *f = new ImapJob ();

  if (f->mJob)
    int b;
}


Compile results with different compilers:
  (Solaris Sun One 8 compiler)
    $ CC -c b.cpp
    "b.cpp", line 22: Error: mJob is not accessible from KMAcctImap::test().
    1 Error(s) detected.
  (HP-UX C++ compiler)
    $ aCC -c b.cpp
    Error 182: "b.cpp", line 22 # "void KMAcctImap::test()" cannot access
    private
        member "KIO::Job *KMail::ImapJob::mJob".
          if (f->mJob)
              ^^^^^^^ 
  (IRIX C++ compiler)
    $ CC -c b.cpp
    cc-1238 CC: ERROR File = b.cpp, Line = 22
      The member "KMail::ImapJob::mJob" is inaccessible.

        if (f->mJob)
               ^
  (IBM C++ compiler)
    $ xlC -c b.cpp
    [success]
  (Tru64 UNIX C++ compiler)
    $ cxx -c b.cpp
    cxx: Error: b.cpp, line 22: member "KMail::ImapJob::mJob" is inaccessible
      if (f->mJob)
    ---------^
  (GCC 3.3.2 with some patches from 3.3.3 merged in)
    $ g++ -c b.cpp
    [success]

I can cause a successful compile by changing:
  namespace KMail {
    class ImapJob {
      friend class KMAcctImap;
to:
  namespace KMail {
    class ImapJob {
      friend class ::KMAcctImap;
                   ^^

So, who is right and why?

-- 
albert chin (china@thewrittenword.com)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]