I have done this assignment as best as i understood it but i am pretty sure there are radical problems. I'll be Looking forward to your comments on how to make it better. The problem definition is as follows:
Two classes. XBoxGame
and WorldPeace
.
Template class called Gift
. Has one method called shake()
. Inside shake()
, we are going to call MakeNoise()
on an instance of our template type T
. ONLY XBoxGame
has MakeNoise()
as a method.
Now in main()
as soon as you try to make a "Gift
that holds an XBoxGame
" (see what I did there?) you'll know if it works when you compile. Try to Gift<WorldPeace>
and it won't compile because MakeNoise()
is missing. What you turn in should just have the correctly templated XBoxGame
class calling shake()
, and a WorldPeace()
that compiles, but only because it is not used in main()
.
End result "You can only put a class that makes noise in a gift". The Code i wrote:
#include <iostream>
class XBoxGame
{
void makeNoise(int,int)
{
std::cout << "Is this Working ? ";
};
};
class WorldPeace
{};
template <typename T>
class Gift
{
public:
T shake()
{
void XboxGame::makeNoise();
}
};
The Main:
#include "Template.h"
using namespace std;
int main()
{
Gift <XBoxGame> ;
Gift <WorldPeace>;
return 0;
}