Skip to content

Instantly share code, notes, and snippets.

@zzt93
Last active August 29, 2015 14:14
Show Gist options
  • Save zzt93/bfe83f12e287350b7d0f to your computer and use it in GitHub Desktop.
Save zzt93/bfe83f12e287350b7d0f to your computer and use it in GitHub Desktop.
Extern const array
#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;
}
#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();
#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