0

Hi, why would this not work? (example)

fileA.h:
// declare the function
void methodA();

fileA.cpp:

// define the function
void methodA(){};

fileX.cpp: 
include "fileA.h"
// call it
methodA(); <--linker error, can't find the symbol

All my headers have the #ifndef guard.
Thanks!

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by IFEEL
0

Hi, why would this not work? (example)

fileA.h:
// declare the function
void methodA();

fileA.cpp:

// define the function
void methodA(){};

fileX.cpp: 
include "fileA.h"
// call it
methodA(); <--linker error, can't find the symbol

All my headers have the #ifndef guard.
Thanks!

Line 13 - is this inside of a function somewhere?
Line 8 - I don't imagine this matters, but you don't need the semicolon.

Line 6 - Do you want #include "fileA.h" here?

I'm not sure how you're compiling this. If you're having an IDE create a makefile for you, without the #include "fileA.h" line in fileA.cpp, I'm not sure that the correct makefile will be created, so it won't link correctly. Try putting that line in, get rid of the semicolon at the end of line 8, and make sure that line 13 is part of a function. Is line 13 in main ()?

Edited by VernonDozier: n/a

0

Ok sry, I found it. I had all of the stuff in the header, in a namespace and forgot that (like classes) the implementation of the function OF COURSE also needs to have namespace::function ...how else would it know where it lies.

Edited by IFEEL: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.