home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!stanford.edu!EE.Stanford.EDU!bbc!danyang
- From: danyang@bbc.Stanford.EDU (Dan Yang)
- Subject: question regarding to template
- Message-ID: <1992Dec11.225733.119@EE.Stanford.EDU>
- Keywords: friend, private member, template
- Sender: danyang@bbc (Dan Yang)
- Organization: Stanford University
- Distribution: su
- Date: Fri, 11 Dec 92 22:57:33 GMT
- Lines: 59
-
-
- --
- Dan Yang
-
-
- I would like to access private member of a template class through friend
- declaration. But ATT compiler gave an compiler error. Here is the
- source code. Thank you for your help!!!
-
-
- #include <stdio.h>
-
- class B;
-
- template <class c>
- class A
- {
- friend B;
- private:
- int i;
- public:
- A(c b) { i = b; a = b; };
- c a;
- };
-
-
- class B
- {
- public:
- int f(A<int> a);
- };
-
-
- int B::f(A<int> a)
- {
- printf("%d\n", a.i);
- return 0;
- }
-
- main()
- {
- A<int> a(10);
- B b;
- b.f(a);
- return 0;
- }
-
-
-
- The error message is :
-
-
- CC test.c:
- "test.c", line 26: error: B::f() cannot access A <int >::i: private member
- "test.c", line 33: warning: b used but not set
- 1 error
-
-
-
-