Somewhat similar to this post, but still different: can I define a global auto
variable in some header file? I tried using the following files, but couldn't make them compile.
$ cat main.cpp
auto a = 5;
#include "defs.h"
int main(int argc, char **argv){ return a; }
$ cat defs.h
#ifndef __DEFS_H__
#define __DEFS_H__
extern auto a;
#endif
And after standard compilation (g++ main.cpp -o main
) I got the following error:
In file included from main.cpp:2:0:
defs.h:3:8: error: declaration of ‘auto a’ has no initializer
extern auto a;
^~~~
Is there any way to define a global auto variable in the source file and include it in some header file? Or will I have to give up this dream and find its type?