Problems compiling world's easiest program
Hi, I'm having trouble compiling my program.
main.cpp file:
Code:
#include <iostream>
#include "Test.h"
using namespace std;
int main()
{
Test a;
a.printSomething();
cout << "Hello World" ;
return 0;
}
Test.h file:
Code:
#ifndef TEST_H
#define TEST_H
class Test
{
public:
void printSomething();
};
#endif
Test.cpp file:
Code:
#include <iostream>
#include "Test.h"
using namespace std;
void Test::printSomething();
{
cout << "Hi";
}
If I comment a.printSomething(); in my main.cpp file, I won't get compilation errors.
But if I do, I get a "Undefined first referenced symbol in file" error :(
Can anyone help?
Okay, compiling with
g++ main.cpp Test.cpp
gives me no errors.
But if I compile using
g++ main.cpp Test.h
I do get errors.
Which is the correct way to compile?