So I am working on this assignment but my professor does not word the instructions very clearly.
I am supposed to have two .cpp files and one header file. One of the .cpp files has the main function and includes the header file. It displays a simple output and then creates an object called "Monster." So in the main .cpp file I call the default constructor and this is where I get confused from the instructions. Is the constructor and destructor supposed to be located in the header file or the other .cpp file?
My code so far is this:
Main.cpp
#include <iostream>
#include <Monster.h>
using namespace std;
int main()
{
cout << "I am going to make a monster!\n";
Monster boggy = Monster();
}
Monster.cpp
#include <iostream>
#include <Monster.h>
using namespace std;
class Monster
{
Monster()
{
cout << "A monster is born!\n;
}
~Monster()
{
cout << "A monster is destroyed!\n;
}
};
Monster.h
class Monster
{
};
class MonsterinMonster.cppdoesn't belong there; It belongs in the header. If you want to put the member function implementation in the.cppfile you can do so, and your text should show you the syntax to do it (which also requires removing those member function bodies from the header once you make the previously mentioned move). Unrelated,Monster boggy = Monster();is pointless. Just useMonster boggy;#include <Monster.h>for your own header files.Monster boggy = Monster();even though it is pointless. So I moved the info from theMonster.cppto theMonster.h