静态函数的定义和调用(捡分的题)
#ifndef __COMOPRE__
//----------------TComOpre.h
#define __COMOPRE__
class TComOpre
{
public:
HANDLE hd_com1,hd_com2;
BOOL opencom(int port);
static CString getvalue();
};
#endif __COMOPRE__
//----------------TComOpre.cpp
#include "stdafx.h"
#include "ComOpre.h"
BOOL TComOpre::opencom(int port)
{
return true;
}
static CString getvalue()
{
return "xxx";
}
//----------------------
xxxx.cpp
#include "TComOpre.h"
....
void CMy008Dlg::Onopen1()
{
CString aa;
aa = TComOpre.getvalue();
}
编译结果如下
------------------------------------------------------------------
--------------------Configuration: 008 - Win32 Debug--------------------
Compiling...
008Dlg.cpp
D:\XJ_Work_Station\test\1127\008\008Dlg.cpp(133) : error C2275: 'TComOpre' : illegal use of this type as an expression
d:\xj_work_station\test\1127\008\comopre.h(5) : see declaration of 'TComOpre'
执行 cl.exe 时出错.
008.exe - 1 error(s), 0 warning(s)