<font color=red>VC 的自定义类模块怎么写??</font> (100分)

C

cat.yy

Unregistered / Unconfirmed
GUEST, unregistred user!
我想自定义一个“类”
“类”中包含几个函数
这个“类”就是一个文件
把这个类加到工程中 可以向引用别的VC的类一样引用它
就象Delphi的单元文件 可以把需要的模块放进去 需要时直接用uses引用即可
请教:<font color=green>VC 中该怎样实现呢</font>??
-----------------------------------------------(VC 的网站象迷宫 又难连 ...)
(强烈建议 DFW 开个 VC分站)
<font size=1><i>
这里是原文 ->
我的创建的方法是:

在“new|project”中选择“建立Lib”
在“class view”中点“new class”; 选择“首标文件”和“MFC类库支持”
填上自定义类 CPCSound (内嵌汇编写的 pc 喇叭发生程序,
没有调用任何VC提供的“类”); 选择"CObject"作为基类 其他均为默认值
在“class view”中右击 添加成员函数 pcSound(...) 类型是void
填充 pcSound 的执行代码
编译(有一个警告)生成.lib文件

--------------
测试类的方法:

建立一个“基于对话框”的应用程序框架
选菜单的“project|add to project|files”,选择加入刚才自建的.lib文件
在该应用程序的 应用程序类的.cpp 文件的头部加上 #include "../xxx/PCSound.h"
位置在该应用程序的 对话框类的 #include "xxxDlg.h" 的前面
给该应用程序添加成员变量 m_pcsSounding 类型是 CPCSound
...
-------------
结果是这样:
当我在程序中 为m_pcsSounding写下“.” 时没有弹出下拉框
强行写 m_pcsSounding.pcSound(...);
编译报8个错(未知类、变量未定义)
-------------
问题是:
要么是没有正确将自建类引入测试程序
要么是自建类根本未建成
</i></font>
 
将你的文件夹下的.opt 和 .ncb删掉。
 
robertcool,
哪个文件夹??
你的意思:我的操作步骤没错??
 
还是不行
 
使用相同的方法将PCSound.h也加经新工程中
 
还不行 以下是系统的提示
-------------------------------------------------------------------
testLib.cpp
..testlib.h(25): error C2146:
syntax error : missing ';' before identifier 'm_pcsSounding'
..testlib.h(25): error C2501:
'CPCSound' : missing storage-class or type specifiers
..testlib.h(25): error C2501:
'm_pcsSounding' : missing storage-class or type specifiers
testLibDlg.cpp
..testlib.h(25): error C2146:
syntax error : missing ';' before identifier 'm_pcsSounding'
..testlib.h(25): error C2501:
'CPCSound' : missing storage-class or type specifiers
..testlib.h(25): error C2501:
'm_pcsSounding' : missing storage-class or type specifiers
..testLibDlg.cpp(176): error C2065:
'm_pcsSounding' : undeclared identifier
..testLibDlg.cpp(176) : error C2228:
left of '.pcSound' must have class/struct/union type
 
说说引入静态库的方法也行呀!
或分析分析错误的可能也行!
 
我觉得是测试程序引入静态库的错
我的测试程序是基于对话框的
怎么写??
(参考书的例子错了 我找不到人问 大家帮忙)
 
在“new|project”中选择“建立Lib”
在“class view”中点“new class”; 选择“首标文件”和“MFC类库支持”
填上自定义类 CPCSound (内嵌汇编写的 pc 喇叭发生程序,
没有调用任何VC提供的“类”); 选择"CObject"作为基类 其他均为默认值
在“class view”中右击 添加成员函数 pcSound(...) 类型是void
填充 pcSound 的执行代码
编译(有一个警告)生成.lib文件

--------------
测试类的方法:

建立一个“基于对话框”的应用程序框架
选菜单的“project|add to project|files”,选择加入刚才自建的.lib文件
在该应用程序的 应用程序类的.cpp 文件的头部加上 #include "PCSound.h"
位置在该应用程序的 对话框类的 #include "xxxDlg.h" 的前面
申明类变量 CPCSound m_pcsSounding;
一切都好了
 
还不行...呜... 谢谢robertcool的关照
我想自定义一个“类”
“类”中包含几个函数
这个“类”就是一个文件
把这个类加到工程中 可以向引用别的VC的类一样引用它
就象Delphi的单元文件 可以把需要的模块放进去 需要时直接用<b>uses</b>引用即可
请教:<font color=green>VC 中该怎样实现呢??</font>
-----------------------------------------------
(VC 的网站象迷宫 又难连 ...)
(强烈建议 DFW 开个 <b>VC分站</b>)
 
申明一各类变量就和Delphi的uses一样了比如有一个类 CPCSound
CPCSound m_pcsSounding;
m_pcsounding.pcsound()就可以用了
 
是这样写的
CPCSound m_pcsSounding;
m_pcsounding.pcsound()
几个错误就是针对它的
我一会把原文件贴给你 看看哪儿写错了
 
#include "../xxxxx/CPCSound.h"了吗?
 
测试文件testLib片段(添加的语句为绿色)

testLib.h
=======================================================================
......
class CTestLibApp : public CWinApp
{
public:
<font color=green>CPCSound m_pcsSounding;</font>
CTestLibApp();
......

testLib.cpp
========================================================================
#include "stdafx.h"
#include "testLib.h"
<font color=green>#include "../xxx/PCSound.h"</font>
#include "testLibDlg.h"
......

testLibDlg.cpp
========================================================================
......
<font color=green>void CTestLibDlg::OnButton1()
{
m_pcsSounding.pcSound(1001.1,400);
}</font>
 
自建类PCSound片段(添加的语句为绿色)

PCSound.h
=======================================================================
......
class CPCsound //: public CObject
{
public:
<font color=green>void pcSound(double dFreq,unsigned short wLong);</font>
CPCsound();
virtual ~CPCsound();
};
......

PCSound.cpp
========================================================================
......
<font color=green>void CPCsound::pcSound(double dFreq, unsigned short wLong)
{
...实现代码
}
</font>
 
对“自建类PCSound”编译通过
对“测试文件testLib”引入“自建类PCSound的 .Lib文件” 编译出8个错
-------------------------------------------
请大家帮忙看看
 
应该将#include "../xxx/PCSound.h"放到文件testLib.h中
 
加了 也不行
 
不要创建类了,将你的函数写到其它头文件算了
 
我试试...
 
顶部