Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #14639
| From | Luca Cerone <luca.cerone@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | static constants are not local to the file they're defined. |
| Date | 2012-03-01 00:28 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <16464242.82.1330590524680.JavaMail.geo-discussion-forums@vbtf25> (permalink) |
Dear all,
I'm a bit confused from the use of static to declare constants that
can be used only by the file they are defined in.
I've made a small test using a main.cpp a mylib.h and a mylib.cpp creating the files like this:
//main.cpp ===============================
#include <iostream>
using namespace std;
#include "mylib.h" ;
int main(){
//L_COS is the constant that I only want to be usable by mylib.cpp
cout << "Hello, World!" << L_COS << endl;
return 0;
}
//mylib.h ===========================
// nothing relevant here, some functions...
// NO declaration of L_COS here.
//mylib.cpp
#include "mylib.h"
static const double L_COS= 1.2345 //my constant.
//I'd like L_COS to be used by the functions in mylib.cpp
//but not in the main.cpp file.
//===========================================
I'd expect that main.cpp doesn't compile. Not only it compiles,
but also print the correct value of L_COS.
So the question is: how can I make L_COS global for all the functions
of mylib.cpp, but not in the scope of any other files?
Thanks a lot in advance,
Luca
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
static constants are not local to the file they're defined. Luca Cerone <luca.cerone@gmail.com> - 2012-03-01 00:28 -0800
Re: static constants are not local to the file they're defined. Robert Wessel <robertwessel2@yahoo.com> - 2012-03-01 02:55 -0600
Re: static constants are not local to the file they're defined. Geoff <geoff@invalid.invalid> - 2012-03-01 01:25 -0800
Re: static constants are not local to the file they're defined. Luca Cerone <luca.cerone@gmail.com> - 2012-03-01 06:51 -0800
Re: static constants are not local to the file they're defined. Christian Gollwitzer <auriocus@gmx.de> - 2012-03-01 19:21 +0100
Re: static constants are not local to the file they're defined. Robert Wessel <robertwessel2@yahoo.com> - 2012-03-01 12:21 -0600
Re: static constants are not local to the file they're defined. Luca Cerone <luca.cerone@gmail.com> - 2012-03-02 00:56 -0800
Re: static constants are not local to the file they're defined. Robert Wessel <robertwessel2@yahoo.com> - 2012-03-02 03:53 -0600
Re: static constants are not local to the file they're defined. Luca Cerone <luca.cerone@gmail.com> - 2012-03-02 02:42 -0800
csiph-web