This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
FRIEND_CLASS_TYPEDEF
- From: Kalugsky Uriy <urik at kiam1 dot rssi dot ru>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 11 Jun 2008 15:18:39 +0400 (MSD)
- Subject: FRIEND_CLASS_TYPEDEF
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.
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 ;
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