I have already checked StackOverflow to find the solution to my problem, but I think I might be missing something. I am trying to define a class in a header file (.h) and implement its methods in a cpp file (.cpp), but it does not work.
main.cpp:
#include <iostream> #include "Message.h" using namespace std; int main() { Message *t = new (Message); t->display(); return 0; } Message.h:
#ifndef MESSAGE_H_INCLUDED #define MESSAGE_H_INCLUDED class Message { public: void display(); }; #endif // MESSAGE_H_INCLUDED Message.cpp:
#include "Message.h" void Message::display() { cout << "Hello!"; } I don't understand why I keep getting the following error
undefined reference to 'Message::display()'