Re: FRIEND_CLASS_TYPEDEF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ho!

--- On Fri, 6/11/08, Kalugsky Uriy <urik@xxxxxxxxxxxxx> wrote:

> Hello,
>
> GCC4.1.0 can't compile the code below.
> It doesn't like the line 'friend class TYPEDEFED_A'.
> Could you explane , please, why.

I think just a common error. Please see below.

> Best regards,
> Yuri
>
> ==================================
> The operating system - Gnu/Linux
> ==================================
>
> GCC Version
> =============================
> g++ (GCC) 4.1.0 (SUSE Linux)
> =============================
>
> The code to compile
> ===================
>
> #include <iostream>
> #include <iomanip>
>
> using namespace std ;
>
> class B ;
> class A
> {
>     public :
>      A(void) {}
>       ~A(void) {}
>
>       void PutInOut(B const &inst) ;
> } ;
> typedef A TYPEDEFED_A ;

The right one should be `typedef class A TYPEDEFED_A;'
I think this should solve your problem. If not, just tell us.

> class B
> {
> ///////////////////////////////////////////////
>     friend class TYPEDEFED_A ;
> //////////////////////////////////////////////
>
>     public :
>     B(void): a(777) {}
>     ~B(void){}
>
>     private :
>       int a ;
> } ;
>
> void TYPEDEFED_A::PutInOut(B const &inst)
> {
>     cout <<"\nB.a " << inst.a << endl ;
> }
>
> int main (int argc, char const *argv[])
> {
>     B b_buf ;
>     TYPEDEFED_A a_buf ;
>
>     a_buf.PutInOut(b_buf) ;
>
>   return 0 ;
> }
>
> Command line
> =============
> g++ -Wall -O -o ./class_typedef ./class_typedef.cpp
>
> The compiler messages
> ========================
> ./class_typedef.cpp:19: error: using typedef-name 'TYPEDEFED_A' after 'class'
> ./class_typedef.cpp:15: error: 'TYPEDEFED_A' has a previous declaration here
> ./class_typedef.cpp:19: error: friend declaration does not name a class or function
> ./class_typedef.cpp: In member function 'void A::PutInOut(const B&)':
> ./class_typedef.cpp:26: error: 'int B::a' is private
> ./class_typedef.cpp:31: error: within this context

Best regards,
Eus


      

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux