Last active
August 29, 2015 14:14
-
-
Save zzt93/bfe83f12e287350b7d0f to your computer and use it in GitHub Desktop.
Extern const array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "extern_const.hpp" | |
const int n = 10; | |
//const int a[] = {1, 2}; // this is also ok | |
extern const int a[] = {1, 2}; | |
int main(int argc, char *argv[]) | |
{ | |
increse(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
extern const int n; | |
extern const int a[1];//or just don't write any size | |
/* error: too many initializers for ‘const int [1]’ | |
extern const int a[] = {1, 2};*/ | |
void increse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "extern_const.hpp" | |
void increse(){ | |
// the n is initialized in extern_const.cpp | |
std::cout << n++ << std::endl;//1.increase const -- error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment