?? subject_34999.htm
字號:
<p>
序號:34999 發(fā)表者:song403 發(fā)表日期:2003-04-03 13:48:17
<br>主題:如何增加自定義的類?
<br>內(nèi)容:我寫了一個類如下:<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>編譯時出現(xiàn)如下錯誤:<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>回復(fù)者:Merlin 回復(fù)日期:2003-04-03 13:52:16
<br>內(nèi)容:在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>
回復(fù)者:韓風(fēng) 回復(fù)日期:2003-04-03 14:18:25
<br>內(nèi)容:樓上忘了一點:<BR><BR>在.cpp中<BR>#include "stdafx.h"<BR>或者不要預(yù)編譯
<br>
<a href="javascript:history.go(-1)">返回上頁</a><br><a href=http://www.copathway.com/cndevforum/>訪問論壇</a></p></blockquote>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -