Forward Declarations in .net

This is a discussion on Forward Declarations in .net within the C++ Programming forums, part of the General Programming Boards category; I need to use a memeber function of a templated class 'B' as a friend function to another templated class ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Forward Declarations in .net

    I need to use a memeber function of a templated class 'B' as a friend function to another templated class 'A'. In order to do this I need to make a forward delcaration of 'B'.

    -For the forward declaration I have:

    template <class T>
    class B;


    -The declaration of the friend function inside 'A'

    friend void B< T >::function();



    This code DOES work when I compile with g++, but in .net when it reaches the friend declaration it says function is not a member function of B. What is the proper syntax to get this working?

    Thanks!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    Is "T" known within A?
    Does it need to be "class T"?

    Also, I'm a bit confused because if B is a forward declaration, then the compiler doesn't know anything about any of B's members.
    Can you post more code so I can try it out in VC++ 6.0

    gg

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    3
    Code:
    // Forward Declaration
    template <class T>
    class B;
    
    
    template < class T >
    class A
    {
         friend void B< T >::function();
    }
    
    
    template < class T >
    class B
    {
         void function();
    }
    Note: You are right in that it shouldn't know that function is a member, I just need to know how to forward declare it so it does

    T is the same for both of them

    Also, the actual bodies of the functions are located at the bottom to maintain abstraction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does gcc hate Forward declarations?
    By SevenThunders in forum C++ Programming
    Replies: 12
    Last Post: 03-16-2009, 02:03 PM
  2. forward class declarations
    By manzoor in forum C++ Programming
    Replies: 17
    Last Post: 12-05-2008, 02:55 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  4. .net
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 02-15-2002, 12:15 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21