On 11.02.2011 13:47, Abdelrazak Younes wrote:
On 02/11/2011 01:41 PM, Enrico Forestieri wrote:
On Fri, Feb 11, 2011 at 01:10:42PM +0100, Abdelrazak Younes wrote:
On 02/11/2011 12:22 PM, Enrico Forestieri wrote:
On Fri, Feb 11, 2011 at 11:07:51AM +0100, Abdelrazak Younes wrote:
On 02/11/2011 01:04 AM, Enrico Forestieri wrote:
On Fri, Feb 11, 2011 at 12:49:22AM +0100, Peter Kümmel wrote:
On 11.02.2011 00:34, Enrico Forestieri wrote:
No, const variables have internal linkage, so they will not be seen outside
their compile unit. Simply declare them as "extern" also in version.cpp.
You mean declaring it in the header as "extern const int i" is the same as
.h: const int i;
.cpp static int i;
No, I mean that if you want a global const variable with external linkage,
the correct C++ way of doing it is
.h extern const int i;
.cpp extern const int i =<value>;
This is misleading, a better fix is to let the cpp file to know
about the header. So #include "version.h" is probably missing in
version.cpp.
No, this is the way it works in C++. Remember that C++ != C :)
C++ = C + +
;-)
I was about to say: Remember that (undefined behavior apart) ++C != C,
but here C++ != C, too.
I am pretty sure the "extern in .h only" works just fine in C++ (I
use that idom in my own pure C++ code). Provided that the compiler
knows about the previous declaration in the header, you don't need
the extern in the source file.
Nope, the extern keyword does name mangling in C++, and that seems
to be true also for MSVC. See:
http://msdn.microsoft.com/en-us/library/357syhfh(v=vs.71).aspx
at the bottom (C and C++ const Differences).
So you are telling me that for during all this time I was using straight C?
No, I would say it was still C++, because in case of C the file with the
definitions doesn't need the header, C would make the const int also visible
in other files.
Peter