🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by rongli Mon, 07 Aug 1995 18:05
Template class as the friend of a template class
#1644
Author: rongli
Date: Mon, 07 Aug 1995 18:05
59 lines
1519 bytes
	The following codes compiled and runs well on Borland C++ but failed
while compiling using gcc-2.6.3:


// test.cc 
#include <iostream.h>

template <class X> 
class B	
{  
  friend class A;
  X data;
public:
  B() : data(1024) {}
  X getData() { return data; }   // I know this will work
};


template <class T, class Y> 
class A
{
  T t;
  B<Y> b;
public:
  void display() { cout << "the data is " << b.data << endl;}
};

void main(void)
{
  A<double, int> a;
  a.display();
  return 0;
}



It gave the error as:

test.cc: In method `void A<double,int>::display()':
test.cc:21: member `data' is a private member of class `B<int>'
gmake: *** [test.o] Error 1

	I know if I used getData(), it would work, but that's not the
way I want. Can some one point out that why  friend class A can not access
data and how to work around other than using getData() ?

	Thanks. 
	



-- 


----------------------------------------------------------------------
 Rong Li			|					 
 rongli@resdgw16.er.usgs.gov	|			
---------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads