public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* FRIEND_CLASS_TYPEDEF
@ 2008-06-11 11:19 Kalugsky Uriy
  0 siblings, 0 replies; 2+ messages in thread
From: Kalugsky Uriy @ 2008-06-11 11:19 UTC (permalink / raw)
  To: gcc-help

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                                                                                                                                  




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FRIEND_CLASS_TYPEDEF
@ 2008-06-16 12:34 Eus
  0 siblings, 0 replies; 2+ messages in thread
From: Eus @ 2008-06-16 12:34 UTC (permalink / raw)
  To: Kalugsky Uriy; +Cc: GCC Help Mailing List

Hi Ho!

--- On Fri, 6/11/08, Kalugsky Uriy <urik@kiam1.rssi.ru> 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


      

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-06-16 12:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11 11:19 FRIEND_CLASS_TYPEDEF Kalugsky Uriy
2008-06-16 12:34 FRIEND_CLASS_TYPEDEF Eus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).