extern auto variable has no initializer

僤鯓⒐⒋嵵緔 提交于 2020-01-04 07:42:41

问题


I need to use a global timestamp (std::chrono::high_resolution_clock::now()) in my c++ program. I declared it in the header file Header.h:

#include<chrono>
using namespace std;
extern auto start;

I want to initialize a value in main, so in main.cpp, I did:

#include"Header.h"
#include<chrono>
using namespace std;
auto start;
int main(){
   start = std::chrono::high_resolution_clock::now();
}

However, when compiling it, I got:

error: declaration of ‘auto start’ has no initializer

Can anybody tell me what I did wrong? Thanks!


回答1:


How is auto supposed to deduce the type of start?
You need to declare the type

extern std::chrono::high_resolution_clock::time_point start;


来源:https://stackoverflow.com/questions/37701323/extern-auto-variable-has-no-initializer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!