#pragma once
#include <ctime>
#include "lib.h"
class testtime
{
public:
int start_s = 0,stop_s = 0;
void starttesttime(){
start_s = clock();
stop_s = 0;
},
stoptesttime(std::string t){
stop_s = clock();
std::cout << t << " time: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) << std::endl;
start_s = 0;
};
};
Run Code Online (Sandbox Code Playgroud)
我得到了严重性代码描述项目文件行抑制状态
Error (active) E0169 expected a declaration test c:\Users\AWW\Desktop\test\test\testtime.h 12 .
Severity Code Description Project File Line Suppression State
Error C2059 syntax error: ',' test c:\users\aww\desktop\test\test\testtime.h 12
Severity Code Description Project File Line Suppression State
Error C2334 unexpected token(s) preceding '{'; skipping apparent function body test c:\users\aww\desktop\test\test\testtime.h 13
Run Code Online (Sandbox Code Playgroud)
我真的宣布了代码.不太确定
在C++中,即使在声明类成员函数时,也可以在一个声明中使用几个逗号分隔的函数声明符.
struct S
{
void foo(), bar(int) const, baz(double, char);
};
/* Same as
struct S
{
void foo();
void bar(int) const;
void baz(double, char);
};
*/
Run Code Online (Sandbox Code Playgroud)
但是,不允许在一个声明中创建几个以逗号分隔的函数定义
struct S
{
void foo() {}, bar(int) const {}, baz(double, char) {}; // ERROR
};
Run Code Online (Sandbox Code Playgroud)
函数定义不是声明符.
您的代码特别受此问题的影响.您试图在一个声明中定义两个void函数.您必须单独定义它们 - 每个定义应该是一个单独的声明.