I cannot get this simple piece of code to compile without including the TestClass.cpp file explicitly in the main.cpp file. What am I doing wrong? Thanks in advance!
Here is the code:
TestClass.h
#ifndef TESTCLASS_H_ #define TESTCLASS_H_ class TestClass { public: static int foo(); }; #endif
Testclass.cpp
#include "TestClass.h" int TestClass::foo() { return 42; }
main.cpp
#include <iostream> #include "TestClass.h" using namespace std; int main() { cout << TestClass::foo() << endl; return 0; }
Here is the error:
g++ main.cpp -o main.app /tmp/ccCjOhpy.o: In function `main': main.cpp:(.text+0x18e): undefined reference to `TestClass::foo()' collect2: ld returned 1 exit status
c ++ include
Scott Mar 26 '09 at 20:27 2009-03-26 20:27
source share