Oct 22, 2014 at 11:38am UTC
how can i access the functions in header to a class in main.cpp
i mean what is the use of header file if i cannot access it on a class
Oct 22, 2014 at 12:21pm UTC
Include the header in main.cpp.
Oct 22, 2014 at 1:00pm UTC
You don't need to declare the prototype as you have it declared in the header that has been included in the source file.
Oct 22, 2014 at 1:10pm UTC
I have no idea why you get an error. Are you sure this is the same code that gave you the error?
Oct 22, 2014 at 1:19pm UTC
@ajh32 oh i see ,about declaring prototype in header
but i think declaring prototype in main instead on header would be more readable
Last edited on Oct 22, 2014 at 1:23pm UTC
Oct 22, 2014 at 1:21pm UTC
@Peter87
yeah this is
why not give me code similar to this
Last edited on Oct 22, 2014 at 1:21pm UTC
Oct 22, 2014 at 1:31pm UTC
@ajh32 oh i see ,about declaring prototype in header
but i think declaring prototype in main instead on header would be more readable
No, just remove the line #5 in the source file as you have the function declared and written in the header, at compile time the #include "a.h" is replaced by the contents of the "a.h" file, in your example as if you had written the addition function at line #3 of your source.
Last edited on Oct 22, 2014 at 1:37pm UTC
Oct 22, 2014 at 1:34pm UTC
The reason I asked was because when I compile your code it compiles without any problems. Could you please post the full error message that you get?
Oct 22, 2014 at 1:41pm UTC
||=== Build: Debug in asd (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `ZN10Calculator7operateEv':|
C:\Users\Lorence\Desktop\asd\main.cpp|14|undefined reference to `addition(int, int)'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
Oct 22, 2014 at 1:45pm UTC
@ajh32
i see but it doesnt work due to my issue