c语言中缺少函数标题,新人求教 错误 timer.h(15) : error C2447: “{”: 缺少函数标题(是否是老式的形式表?)...

使用 'Microsoft Visual C++ 2013 Professional' 编译。

timer.h文件源码如下

#ifndef _TIMER_H_

#define _TIMER_H_

#include

#include

//#include //windows下的time.h中没有timeval定义

#include //windows下代替

#include //windows下代替

using namespace std;

//windows下没有gettimeofday函数,从网上找的一个替代函数

int gettimeofday(struct timeval *tp, void *tzp)  //第15行

{

time_t clock;

struct tm tm;

SYSTEMTIME wtm;

GetLocalTime(&wtm);

tm.tm_year = wtm.wYear - 1900;

tm.tm_mon = wtm.wMonth - 1;

tm.tm_mday = wtm.wDay;

tm.tm_hour = wtm.wHour;

tm.tm_min = wtm.wMinute;

tm.tm_sec = wtm.wSecond;

tm. tm_isdst = -1;

clock = mktime(&tm);

tp->tv_sec = clock;

tp->tv_usec = wtm.wMilliseconds * 1000;

return (0);

}

class timer {

public:

int gettimeofday(struct timeval *tp, void *tzp);

timer(string timer_name) {

name = timer_name;

total_time = 0;

calls = 0;

}

~timer() {};

void tic() {

struct timeval tv;

gettimeofday(&tv, NULL);

last_time = (double)tv.tv_sec + 1e-6*(double)tv.tv_usec;

calls++;

}

void toc() {

struct timeval tv;

gettimeofday(&tv, NULL);

double cur_time = (double)tv.tv_sec + 1e-6*(double)tv.tv_usec;

total_time += cur_time - last_time;

}

const char *msg() {

ostringstream oss;

oss << "timer '" << name

<< "' = " << total_time << " sec in "

<< calls << " call(s)";

return oss.str().c_str();

}

void mexPrintTimer() {

mexPrintf("timer '%s' = %f sec in %d call(s)\n", name.c_str(), total_time, calls);

}

double getTotalTime() {

return total_time;

}

private:

string name;

int calls;

double last_time;

double total_time;

}

#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值