Answer to Question #201354 in C++ for Arjun

Question #201354

Define a class template named Alice that takes a single type parameter. Make Alice a friend of all instances of a template class named Friendly. Give Alice member functions that demonstrate its friendship.



1
Expert's answer
2021-06-01T02:58:20-0400
#include <iostream>
using namespace std;
class Friendly;
template <class T>
class Alice
{
private:
	T x;
	friend class Friendly;
public:
	Alice() : x(10) {}
};
class Friendly {
    private:
        int y;


    public:
    Friendly() : y(13) {}
    int add() {
        Alice<int> obj;
        return obj.x + y;
    }
};
int main(){


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog