FRIEND_CLASS_TYPEDEF

Kalugsky Uriy urik@kiam1.rssi.ru
Wed Jun 11 11:19:00 GMT 2008


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                                                                                                                                  






More information about the Gcc-help mailing list