|
-
February 9th, 2011, 03:38 AM
#4
Re: Confused with linking header file in C++
 Originally Posted by ritika_sharma82
But now, I wanna call a "const int" data declared in header1.h from main.cpp.
I tried including header1.h in main.cpp, it shows the error. It says redefined.
Strange. I should say that the "const int" isn't initialized.
A const declaration should look like this,
const int someData = 43;
and you should be able to include it in many compilation units (like main.cpp and function.cpp) you then link.
It's only if someData isn't const you should need to declare it extern. In that case you make sure that this is in one compilation unit only,
int someData;
and that all compilation units who want to use someData incude this,
extern int someData;
Last edited by nuzzle; February 9th, 2011 at 03:43 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|