小弟初学vc,想写一个新类,继承CString,然后添加一个toInt()方法,把CString直接转成int格式,但是新建的项目什么都没写就编译不过去了,查了资料有人这样说的通过任何一种新建类的办法创建CString派生类后(如果基类没有CString,就任选一个MFC类,最后把.h和.cpp中的所有基类全部替换为CString类),在StdAfx.h加入#include <afx.h>即可!
小弟再vc2005里面建立一个新项目,再类试图按照上面的步骤做好了,但是编译出现如下错误,恳请高手指点[code=INIFile]1>------ 已启动生成: 项目: TestDim, 配置: Debug Win32 ------
1>正在编译...
1>stdafx.cpp
1>正在编译...
1>TestDim.cpp
1>TestDimDlg.cpp
1>Dim.cpp
1>g:\vs2005\project\testdim\dim.cpp(11) : error C2039: 'GetThisClass' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>g:\vs2005\project\testdim\dim.cpp(24) : error C2039: 'GetThisMessageMap' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>Generating Code...
1>生成日志保存在“file://g:\VS2005\Project\testDIM\Debug\BuildLog.htm”
1>TestDim - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========[/code]
小弟再vc2005里面建立一个新项目,再类试图按照上面的步骤做好了,但是编译出现如下错误,恳请高手指点[code=INIFile]1>------ 已启动生成: 项目: TestDim, 配置: Debug Win32 ------
1>正在编译...
1>stdafx.cpp
1>正在编译...
1>TestDim.cpp
1>TestDimDlg.cpp
1>Dim.cpp
1>g:\vs2005\project\testdim\dim.cpp(11) : error C2039: 'GetThisClass' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>g:\vs2005\project\testdim\dim.cpp(24) : error C2039: 'GetThisMessageMap' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>Generating Code...
1>生成日志保存在“file://g:\VS2005\Project\testDIM\Debug\BuildLog.htm”
1>TestDim - 2 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========[/code]
int num = atoi(str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
int num = atoi(str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
===============================================
其实,我是有个大计划....写一个通用数据类型的类,不管是什么类型,都可以通过toXXXX来转换,需要什么就转什么,继承CString只是一个测试....