where should we use a 'friend' class and when should inheritance be used?
where should we use a 'friend' class and when should inheritance be used?
friend function, not class. You declare a function friend when you want to give it access to private data members of more than one class.
I suck at OOP
edit:and I/O
>> friend function, not class.
You can have friend classes as well.
>> where should we use a 'friend' class and when should inheritance be used?
These are vague questions that aren't really related. Are you asking about scenarios where both will work?
daved put it more clear that is what i wanted to indicate that be more specific because we are not supposed to lecture you on the topic of friend versus inheritance.
Inheritance is when two or more classes can "share" protected data members or functions. This is helpful in some circumstances if you are creating multiple classes which will have similar attributes.
Code:class Mamal { protected: int age; std::string name; }; // dog class now have access to age and name class Dog : public Mamal
Double Helix STL
Read the C++ FAQs regarding inheritance, especially the ones regarding proper inheritance and substitutability, otherwise you'll be back here in a few days asking how to use dynamic_cast. Inheritance is more than just re-using functions and data, but unfortunately it is often abused.