FRIEND_CLASS_TYPEDEF
Eus
eus@member.fsf.org
Tue Jun 17 07:48:00 GMT 2008
Hi Ho!
--- On Mon, 6/16/08, Kalugsky Uriy <urik@kiam1.rssi.ru> wrote:
> From: Kalugsky Uriy <urik@kiam1.rssi.ru>
> Subject: Re:Re:FRIEND_CLASS_TYPEDEF
> To: eus@member.fsf.org
> Date: Monday, June 16, 2008, 9:19 PM
> Hello,
>
> I tried 'typedef class A TYPEDEFED_A'. It
> doesn't work.
> Compilation was finished with messages:
> ./class_typedef.cpp:19: error: using typedef-name
> 'TYPEDEFED_A' after 'class'
I don't know what the C++ standard says, but looking at the error message, I can only think that you cannot use an identifier that is defined with `typedef' after the `class' keyword of `friend'. Please correct me if I am wrong.
As a proof, when I changed `friend class TYPEDEFED_A' to `friend class A', the use of `TYPEDEFED_A a_buf;' in `main()' works perfectly fine.
BTW, IMHO, it would be better if you still type `class A' instead of making it opaque through the use of `typedef class A TYPEDEFED_A' so that other people can readily spot that `A' is actually a `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
>
>
>
>
>
> Compilation exited abnormally with code 1 at Mon Jun 16
> 18:15:01
>
>
>
> If the line 'friend class TYPEDEFED_A' changes to
> 'friend TYPEDEFED_A'
> Compilation will be finished with messages:
>
> ./class_typedef.cpp:19: error: a class-key must be used
> when declaring a friend
>
>
> ./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
>
>
>
>
>
> Compilation exited abnormally with code 1 at Mon Jun 16
> 18:11:57
>
>
>
> 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 class A TYPEDEFED_A ;
>
> 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
More information about the Gcc-help
mailing list