L
Luca Cerone
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
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