⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_34999.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:34999 发表者:song403 发表日期:2003-04-03 13:48:17
<br>主题:如何增加自定义的类?
<br>内容:我写了一个类如下:<BR>//This is a class of gpib <BR>#include &lt;afxwin.h&gt;<BR>#include "Decl-32.h"<BR><BR><BR><BR>class GPIB<BR>{<BR><BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;static int BUFFER_SIZE;<BR>&nbsp;&nbsp;&nbsp;&nbsp;static int GPIB0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Addr4882_t HP_SIGNAL_GENERATOR;<BR>private:<BR>&nbsp;&nbsp;&nbsp;&nbsp;static bool isOpen;<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;GPIB(){};<BR>&nbsp;&nbsp;&nbsp;&nbsp;~GPIB() {};<BR>&nbsp;&nbsp;&nbsp;&nbsp;static bool Open();<BR>&nbsp;&nbsp;&nbsp;&nbsp;static void Close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;static void GPIBCleanup();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;bool WriteGPIB(const CString &amp;strCmd,Addr4882_t addr);<BR>&nbsp;&nbsp;&nbsp;&nbsp;bool ReadGPIB(CString &amp;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>&nbsp;&nbsp;&nbsp;&nbsp;if(!isOpen)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SendIFC(GPIB0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (ibsta &amp; ERR)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GPIBCleanup();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isOpen=true;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;EnableRemote(GPIB0,HP_SIGNAL_GENERATOR);<BR>&nbsp;&nbsp;&nbsp;&nbsp;return isOpen;<BR>}<BR><BR>void GPIB::Close()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(isOpen)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ibonl(GPIB0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isOpen=false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>}<BR><BR>void GPIB::GPIBCleanup()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Close();<BR>}<BR><BR>bool GPIB::WriteGPIB(const CString &amp;strCommand,Addr4882_t addr)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;CString strCmd=strCommand;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int len=strCmd.GetLength();<BR>&nbsp;&nbsp;&nbsp;&nbsp;PSTR pCmd=strCmd.GetBuffer(len+1);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;Send(GPIB0,addr,PVOID(pCmd),len,NLend);<BR>&nbsp;&nbsp;&nbsp;&nbsp;strCmd.ReleaseBuffer();<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(ibsta &amp; ERR)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GPIBCleanup();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return true;<BR>}<BR><BR>bool GPIB::ReadGPIB(CString &amp;strResponse,Addr4882_t addr,int size)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Receive(GPIB0,addr,PVOID(strResponse.GetBuffer(size+1)),long(size),STOPend);<BR>&nbsp;&nbsp;&nbsp;&nbsp;strResponse.ReleaseBuffer();<BR>&nbsp;&nbsp;&nbsp;&nbsp;strResponse.Replace('\r','\0');<BR>&nbsp;&nbsp;&nbsp;&nbsp;strResponse.Replace('\n','\0');<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;if(ibsta &amp; ERR)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GPIBCleanup();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;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 + -