[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hpux-devtools
Subject:    Re: Fw: HPUX-DEVTOOLS: need some help (related to C++)
From:       Rakesh J Chella <rakesh () versant ! com>
Date:       2002-08-07 7:06:37
[Download RAW message or body]


The mailing list for C++ related queries would be cxx-dev@cxx.cup.hp.com

-Rakesh

On Wed, 7 Aug 2002, Eswaran S.K. wrote:

> Date: Wed, 7 Aug 2002 11:46:32 +0530
> From: Eswaran S.K. <sk_eswaran@hotmail.com>
> To: hpux-devtools@cxx.cup.hp.com
> Subject: Fw: HPUX-DEVTOOLS: need some help (related to C++)
> 
> ok one more thing
> 
> if a() constructor is reimplemented as
> /*===========================================*/
> contain::a::a() : m_p(NULL)
> {
>    m_p = new b();
> }
> /*===========================================*/
> 
> it works find in Windows (Microsoft VC++)
> but fails in Sun CC, and aCC
> 
> - eswar
> 
> ----- Original Message ----- 
> From: Eswaran S.K. 
> To: hpux-devtools@cxx.cup.hp.com 
> Sent: Wednesday, August 07, 2002 11:35 AM
> Subject: HPUX-DEVTOOLS: need some help (related to C++)
> 
> 
> hi ppl.
> 
> thanx for all immediate responses i have got...
> 
> i have a small problem in hand...
> in the code below, i have tried to 
> 
> to restrict a class (class b) visible only to the classes defined in class contain.
> (similar to package scope in java)
> 
> but i get the following compilation error
> /*================================================================================*/
> Error 182: "test.cpp", line 15 # class a cannot access  private member class b.
>          b *m_p;
>          ^
> Error 182: "test.cpp", line 40 # "contain::a::a()" cannot access private member class b.
>        m_p = new contain::b();
>                  ^^^^^^^^^^
> /*================================================================================*/
>  
> i want to know if there is a solution to this...
> or is there any design concept to acheive the same.
> 
> code section follows...
> 
> thanx in advance
> - eswar
>  
> /*================================================================================*/
> # include <stdio.h>
> 
> class contain
> {
>   /*forward declaration of class b
>   note it is private, i dont want outside world
>   (apart from Container classes to access class b)*/
>   private:
>     class b;
> 
>   public:
>   class a
>   {
>      b *m_p;
>      public:
>          a();
>          virtual ~a();
>          void func()
>          {
>             if ( m_p ) printf("%d",m_p->i); 
>          }
>   };
> 
>   private:
>   class b
>   {
>     friend class a;
>     private:
>        int i;
>     public:
>         b():i(0) {}
>   };
> 
> 
> };
> 
> contain::a::a() : m_p(NULL)
> {
>    m_p = new contain::b();
> }
> contain::a::~a()
> {
>   if ( m_p ) delete m_p;
> }
> 
> int main()
> {
>    contain::a obja;
>    obja.func();
>    return 0;
> }
> /*================================================================================*/
> 
> 

 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE hpux-devtools
 _________________________________________________________________
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic