CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jul 2017
    Location
    Greece
    Posts
    130

    Force a friend outside of class declaration?

    Is it possible to force a class to have a friend class or friend function outside of this class declaration?

    For example

    Code:
    class MyClass
    {
     . . .
    
    private:
        int m_id = 0;
    
    };
    
    
    //Somewhere else
    force MyClass to have friend int AccessPrivateSruff(const MyClass& obj);
    
    
    int AccessPrivateSruff(const MyClass& obj)
    {
        return obj.m_id;
    }
    The reason I want to do that, is because I'm writting a unit test framework and
    I want somehow to add my unit test class as a friend to the classes that I'm testing
    but I dont want to change the declarations of the actual classes that I'm testing.

    It does not make sense my actual application classes to have friends of the testing framework,
    since the testing framework is not part of the application.
    Last edited by babaliaris; September 27th, 2020 at 09:25 AM.

Tags for this Thread

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