CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2002
    Location
    Hyderabad, India
    Posts
    2

    friends in class templates

    hello,
    i have two template functions declared like below.

    //////////////////

    template <class A, class B>
    void f1 (void);

    template <class A, class B>
    void f2 (void);

    /////////////////////

    and i have a class template as below


    //////////////////////////

    template <class T>
    class test {
    //.....
    public:

    // two friend declarations required here for f1 & f2;
    };


    /////////////////////////


    i want the friend declarations in such a way that f1<XXX,YYY> can access private members of test<YYY> only, it can't have access to test<XXX> class;

    similarly t2<AAAA,BBBB> should have acces to test<AAAA> only.


    You got my question? how should i achieve this? how should be the friend declarations for f1, f2 functions in class test?

    Please I really want this. Please give me a detailed explanation.

    Thank you very much.

    -Chaitu

  2. #2
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: friends in class templates

    I'm not sure that it can be done, and certainly not all compilers support it.

    It is quite possible that what you are doing can (and should) be done in another way. After all, the template function would have to know enough detail of your class to know what private features it wants to access, and the coupling is therefore fairly tight here. Perhaps, therefore, t1 and t2 should both therefore be template member functions of the classes that they are supposed to have the access to. Otherwise, is there no way they can do what they are trying to achieve with public members?

    I'd have to see your exact example to help determine how else you could achieve that which you are trying to do.


    The best things come to those who rate

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured