Hi, I'm having trouble compiling my program.
main.cpp file:
Test.h file:Code:#include <iostream> #include "Test.h" using namespace std; int main() { Test a; a.printSomething(); cout << "Hello World" ; return 0; }
Test.cpp file:Code:#ifndef TEST_H #define TEST_H class Test { public: void printSomething(); }; #endif
If I comment a.printSomething(); in my main.cpp file, I won't get compilation errors.Code:#include <iostream> #include "Test.h" using namespace std; void Test::printSomething(); { cout << "Hi"; }
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?



LinkBack URL
About LinkBacks




