Topic: Different access in different modules


Author: bonnardv@pratique.fr (Valentin Bonnard)
Date: 1996/11/11
Raw View
Jean-Louis Leroy wrote:
> must the acessibility of a member function agree across modules? Is the
> following program legal?
>
> // module1.cpp
>
> struct X
>  {
>  public:
>   void f();
>
>   friend void g();
>  };
>
[...]
>
>  // module2.cpp
>
> struct X
>  {
>  private:
>   void f();
>
>   friend void g();
>  };
>
[...]

Obviously X is defined differently in the two files so it break the
ODR (One Definition Rule), so the program is definitely illegal.

--

Valentin Bonnard
mailto:bonnardv@pratique.fr
http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Jean-Louis Leroy <100611.1330@compuserve.com>
Date: 1996/11/07
Raw View
Hello,

must the acessibility of a member function agree across modules? Is the
following program legal?

// module1.cpp

struct X
 {
 public:
  void f();

  friend void g();
 };

void X::f()
 {
 }

int main()
 {
 X x;
 x.f();
 g();
 return 0;
 }

 // module2.cpp

struct X
 {
 private:
  void f();

  friend void g();
 };

void g()
 {
 X x;
 x.f();
 }

jl
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Steve Downey" <steve.downey@servicing.com>
Date: 1996/11/08
Raw View
Nope. It violates the one definition rule.

Jean-Louis Leroy <100611.1330@compuserve.com> wrote in article
<VA.00000005.012d4460@enterprise>...
> Hello,
>
> must the acessibility of a member function agree across modules? Is the
> following program legal?
>
> // module1.cpp
>
> struct X
>  {
>  public:
>   void f();

....

>  // module2.cpp
>
> struct X
>  {
>  private:
>   void f();



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: clamage@taumet.Eng.Sun.COM (Steve Clamage)
Date: 1996/11/08
Raw View
In article 012d4460@enterprise, Jean-Louis Leroy <100611.1330@compuserve.com> writes:
>Hello,
>
>must the acessibility of a member function agree across modules?

Yes.

According to the One-Definition Rule, all definitions for the same class
must agree, or the program behavior is undefined. As a practical matter, you
might get away with violating the rule in the way you suggest, but you can't
count on it, and it is certainly a Bad Programming Practice.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]