A class – how to encourage to be also a friend?

Introduction
What do you think about programming ? Did I encourage you to increase your knowledge on this field ? πŸ™‚ If your answer is: YES –Β  I am very happy, if: NO – unfortunately, maybe programming is not for you or you should find another more interesting source to know more about programming and … someday make an application which will solve a common problem πŸ™‚
In this post I want to show you and explain to you how to create a friend class. If you are interested in the topic – follow me πŸ˜‰

Programming
On starting, let’s come back to code from a previous post.

I am going to modify this code. Add a new class and then I will try to make a class friendly.Β It is high time to ‘connect’ both classes. How can you do it ? Do you remember how looks like a process of connecting functions ? If you are not sure, check here. It will be little similar like in functions. Firstly, you have to add the line:
Now, in the function ‘void price_news()’ you will have to give a parameter.
Obviously, naming of a reference depends only you so instead ‘Fruits & fo‘ you could use ‘Fruits & frts‘. You have a choice πŸ™‚ .
You can write anything in the method. I have added this:
Currently, you have a chance to create an object and refer to…
Firstly, create an object in ‘int main’.
Undoubtedly, you noticed that Visual Studio shows you have to write something yet in ‘new_apple.price_news()‘. What you should write there (give as an argument) ? Think for a moment…

You have to give as an argument just the object apple. Check your code by clicking CTRL+F5. In my Visual Studio, there aren’t any mistakes.

If you are not sure, start one more time. However, any questions please leave in a commnet field or go toΒ contact and write there a message.

Leave a comment