【发布时间】:2016-10-08 15:39:15
【问题描述】:
我需要在我的 c++ 程序中使用全局时间戳 (std::chrono::high_resolution_clock::now())。我在头文件 Header.h 中声明了它:
#include<chrono>
using namespace std;
extern auto start;
我想在main中初始化一个值,所以在main.cpp中,我做了:
#include"Header.h"
#include<chrono>
using namespace std;
auto start;
int main(){
start = std::chrono::high_resolution_clock::now();
}
但是,在编译时,我得到了:
error: declaration of ‘auto start’ has no initializer
谁能告诉我我做错了什么?谢谢!
【问题讨论】:
-
较新的问答有更好的答案(和更清晰的问题 IMO)。