📄 subject_34999.htm
字号:
<p>
序号:34999 发表者:song403 发表日期:2003-04-03 13:48:17
<br>主题:如何增加自定义的类?
<br>内容:我写了一个类如下:<BR>//This is a class of gpib <BR>#include <afxwin.h><BR>#include "Decl-32.h"<BR><BR><BR><BR>class GPIB<BR>{<BR><BR>public:<BR> static int BUFFER_SIZE;<BR> static int GPIB0;<BR> Addr4882_t HP_SIGNAL_GENERATOR;<BR>private:<BR> static bool isOpen;<BR>public:<BR> GPIB(){};<BR> ~GPIB() {};<BR> static bool Open();<BR> static void Close();<BR> static void GPIBCleanup();<BR><BR> bool WriteGPIB(const CString &strCmd,Addr4882_t addr);<BR> bool ReadGPIB(CString &response,Addr4882_t addr,int size=BUFFER_SIZE);<BR>};<BR><BR><BR>CPP文件如下:<BR><BR>#include "gpib.h"<BR><BR>bool GPIB::isOpen=false;<BR><BR>BUFFER_SIZE=32000;<BR>GPIB0=0;<BR>HP_SIGNAL_GENERATOR=6;<BR><BR>bool GPIB::Open()<BR>{<BR> if(!isOpen)<BR> {<BR> SendIFC(GPIB0);<BR> if (ibsta & ERR)<BR> GPIBCleanup();<BR> else<BR> isOpen=true;<BR> }<BR> EnableRemote(GPIB0,HP_SIGNAL_GENERATOR);<BR> return isOpen;<BR>}<BR><BR>void GPIB::Close()<BR>{<BR> if(isOpen)<BR> { <BR> ibonl(GPIB0,0);<BR> isOpen=false;<BR> }<BR>}<BR><BR>void GPIB::GPIBCleanup()<BR>{<BR> Close();<BR>}<BR><BR>bool GPIB::WriteGPIB(const CString &strCommand,Addr4882_t addr)<BR>{<BR> CString strCmd=strCommand;<BR> int len=strCmd.GetLength();<BR> PSTR pCmd=strCmd.GetBuffer(len+1);<BR><BR> Send(GPIB0,addr,PVOID(pCmd),len,NLend);<BR> strCmd.ReleaseBuffer();<BR> if(ibsta & ERR)<BR> {<BR> GPIBCleanup();<BR> return false;<BR> }<BR> return true;<BR>}<BR><BR>bool GPIB::ReadGPIB(CString &strResponse,Addr4882_t addr,int size)<BR>{<BR> Receive(GPIB0,addr,PVOID(strResponse.GetBuffer(size+1)),long(size),STOPend);<BR> strResponse.ReleaseBuffer();<BR> strResponse.Replace('\r','\0');<BR> strResponse.Replace('\n','\0');<BR><BR> if(ibsta & ERR)<BR> {<BR> GPIBCleanup();<BR> return false;<BR> }<BR> return true;<BR><BR>}<BR>编译时出现如下错误:<BR>fatal error C1010: unexpected end of file while looking for precompiled header directive<BR><BR><BR>error C2011: 'GPIB' : 'class' type redefinition<BR><BR>该如何解决。
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Merlin 回复日期:2003-04-03 13:52:16
<br>内容:在gpib.h中加入<BR>#ifndef _GPIB_H_<BR>#define _GPIB_H_<BR>..<BR>...<BR>..<BR>类声明<BR>..<BR>..<BR>#endif //_GPIB_H_
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:韩风 回复日期:2003-04-03 14:18:25
<br>内容:楼上忘了一点:<BR><BR>在.cpp中<BR>#include "stdafx.h"<BR>或者不要预编译
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -