How to use a Friend function within a class

Asked

Viewed 99 times

0

My program is structured as follows :

Classe.cpp // Implementation of class methods

Classe.hpp // Prototypes of the class

Main.cpp // Main file

In my file Classe.hpp I have the prototype a function friend :

friend int mdc(int, int);

The implementation of this function is in Main.hpp, the question here is : how can I use this function in my file Classe.cpp ?

I tried using the pointer this-> and :

Was not declared in this scope

I researched, but the doubts I found dealt with other aspects of functions friend, moreover I was vehemently instructed not to carry out the implementation of such a function within my class. How can I accomplish this ?

  • A function marked as friend is not part of the class, it just means that the Friend function has access to class internals.

  • In short : impossible to accomplish what I want ?! ( I think I will have to put the same in an external module to main )

  • That sounds like the problem XY. Ask a question with what you really want to solve.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.