关于C++的static

来源:互联网 发布:好听的淘宝会员名 编辑:程序博客网 时间:2024/06/01 07:42

今天打算在一个项目里面写个自己的类,结果发觉C++的类忘记了很多(看来不能总是跟java打交道,不然很容易把C++跟java的类搞混)

TimeCal.h
class TimeCal{public: TimeCal(); static int64 st,et; static void console_printf(int64 s1,int64 s2);};

注意当中定义了两个static的变量,如果定义了变量的话,一定要在TimeCal.cpp里面进行定义,如果不定义的话会出现

错误6:error LNK2001: 无法解析的外部符号 "public: static __int64 TimeCal::st" (?st@TimeCal@@2_JA)F:\txpj\Stich_GUI\Stich_GUI\Stich_GUIDlg.obj

这种错误。

#include "TimeCal.h"TimeCal::TimeCal(){}void TimeCal::console_printf(int64 s1,int64 s2){AllocConsole(); // 打开控制台资源freopen( "CONOUT$", "w+t", stdout );// 申请写freopen( "CONIN$", "r+t", stdin ); // 申请读printf("Initial time: %f\n", ((s2-s1)/(double)cvGetTickFrequency())/1000.0);char ch = getchar(); // 读数据FreeConsole(); // 释放控制台资源}
写完这里就可以在你的程序中直接使用TimeCal::st以及TimeCal::console_printf了。。

0 0
原创粉丝点击