suiguodang9873 2017-10-30 00:55 采纳率: 0%
浏览 10597

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

error C2447: “{”: 缺少函数标题(是否是老式的形式表?)

  • 写回答

2条回答

  • threenewbee 2017-10-30 01:11
    关注

    类定义结束没有分号

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制