unavailability of global variables in other .h files
1.shouldn't symbolic constants and global variables be available in other .h files if they're declared in main.cpp before including header files?
#ifndef PI
#define PI 314
#endif
const int global_const = 4;
#include <iostream>
using namespace std;
#include "test.h"
int main() {
test ob;
cout << ob.f();
return 0;
}
#ifndef CONST_OOP_TEST_H #define CONST_OOP_TEST_H class test { public: int f ( ){ return global_const * PI; } }; #endif //CONST_OOP_TEST_H
2.when I compile my program in terminal using g++
g++ main.cpp -o output
it compiles with no error
but when i try to compile it in clion it mentions
no global_const is defined
no PI is defined
and it prevents me from compiling how to bypass this error in clion because clearly no one prefers to compile in terminal each time
请先登录再写评论。