T.T*_*.T. 0 c variables syntax external global-variables
档案1:
static char* const path; //GLOBAL
int main()
{
path = FunctionReturningPath();
UsePath()
}
Run Code Online (Sandbox Code Playgroud)
文件2:
extern char* const path; //GLOBAL from file 1
UsePath() //function using global
{
something = path;
}
Run Code Online (Sandbox Code Playgroud)
(伪)
想在文件2中使用路径.
我在主文件1中定义全局,是使用全局的不良做法吗?
并且不编译:
Compile Error: error LNK2001: unresolved external symbol _path
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.谢谢.
小智 6
static char* path; //GLOBAL
Run Code Online (Sandbox Code Playgroud)
错误.使其静态意味着它是文件的本地,并且不能使用extern公开.你要:
char* path; //GLOBAL
Run Code Online (Sandbox Code Playgroud)