I'm new to programming with header files in C ++. This is my current code:
// a.h #ifndef a_H # A_H namespace Hello {class A {int a; Public: zero set A (int x); Int getA (); }; } #endif //a.cpp # Include "a.h" namespace Hello {A :: Set A (int x) {a = x; } Int A :: getA () {Return; }} //ex2.cpp #include "a.h" #includes & lt; Iostream & gt; using namespace std; Name Location Hello {A * a1; } Hello using the namespace; Int main () {a1 = new A (); A1- & gt; Seta (10); The court's & lt; & Lt; A1- & gt; Geta (); Return 1; }
When I try to compile it with g ++ ex2.cpp
, I get this error:
'Main' in the function: Ex2.cpp: (text + 0x33): Undefined context for 'hello :: a :: set a (int)': 'ex2.cpp :(. Text + 0x40):' Hello :: A :: Mill A () 'Collection 2: LD returned 1 exit status
Why is it not working, and how can I fix it?
You do not link header files You can link object file Which are created by compiling the .cpp
files. You have to compile all your source files and pass the resultant files on the linker.
By the error message it seems that you are using GCC. If so, then I think that you can compile both .cpp
.cpp
and file with result Object Files can open Linker
Comments
Post a Comment