软件注册站
热情软件屋

 
error C2511: overloaded member function 'void (char *)' not found in 'CSearchDlg'
编号: QA004896    
建立日期: 2004年9月4日 最后修改日期: 2004年9月4日
所属类别: C/C++ - 错误信息
   
    操作系统: windowsxp
    编程工具: vc++6
    问题: 和你们的QA004551 "编译时出错:cannot convert parameter 1 from *** to ***"所说的错误相似,但是我试了不行,麻烦看一下:是关于“http://www.enet.com.cn/eschool/inforcenter/A20040215286381_1.html
    我跟着做,直接复制的就会很多错误,我解决的不少,但是还是有一个错误:
    --------------------Configuration: search - Win32 Debug--------------------
    Compiling...
    searchDlg.cpp
    D:\VSOUT\search\searchDlg.cpp(178) : error C2511: 'Search_Directory' : overloaded member function 'void (char *)' not found in 'CSearchDlg'
     d:\vsout\search\searchdlg.h(14) : see declaration of 'CSearchDlg'
    Error executing cl.exe.
    
    search.exe - 1 error(s), 0 warning(s)
    
    文件searchDlg.h部分如下
    class CSearchDlg : public CDialog
    
{
    
// Construction
    
public:
    
__stdcall CSearchDlg(CWnd* pParent = NULL); // standard constructor
    
__stdcall Search_Directory(char);
    

    
    文件searchDlg.cpp部分:
    #include "stdafx.h"
    
#include "search.h"
    
#include "searchDlg.h"
    
#include "io.h"
    
#include "direct.h"
    
    
    
……
    
    
    
void CSearchDlg::Search_Directory(char* szFilename)
    
{
    
long handle; //问题就是这里!
    
struct _finddata_t filestruct;
    
char path_search[_MAX_PATH];
    
handle = _findfirst("*", &filestruct);
    
if((handle ==-1)) return;
    
if( ::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY )
    
{
    
if( filestruct.name[0] != '.' )
    
{
    
_chdir(filestruct.name);
    
Search_Directory(szFilename);
    
_chdir("..");
    
}
    
}
    
else // 如果第一个实体不是目录, 则检查是否是要查找的文件
    
{
    
if( !stricmp(filestruct.name, szFilename) )
    
{
    
strcat(path_search,"\\");
    
strcat(path_search,filestruct.name);
    
AfxMessageBox(path_search); //输出显示
    
}
    
}
    
while(!(_findnext(handle,&filestruct)))
    
{
    
if(::GetFileAttributes(filestruct.name) & FILE_ATTRIBUTE_DIRECTORY )
    
{
    
if(*filestruct.name != '.')
    
{
    
_chdir(filestruct.name);
    
Search_Directory(szFilename);
    
_chdir("..");
    
}
    
}
    
else
    
{
    
if(!stricmp(filestruct.name,szFilename))
    
{
    
_getcwd(path_search,_MAX_PATH);
    
strcat(path_search,"\\");
    
strcat(path_search,filestruct.name);
    
AfxMessageBox(path_search);
    
}
    
}
    
}
    
_findclose(handle);
    
}
    
    
    
    
    
    
    
void CSearchDlg::OnButton1search()
    
{
    
char szFilename[80];
    
strcpy(szFilename,"Mytext.txt");
    
_chdir("d:\\"); // 进入要查找的路径(也可为某一具体的目录)
    
Search_Directory(szFilename[80]);
    
MessageBox("查找文件完毕!");
    
}
    
    

    
    水平: 刚入门
    (叶城)
   
    问题出在你的searchDlg.h中Search_Directory的定义。你在头文件中加了__stdcall,而在.cpp中没有加,这样就对于.cpp中的Search_Directory使用的是__cdecl方式,两个不一致,所以报告错误。如果删除了__stdcall,还是有错误。因为你在.cpp中函数返回值声明为void,而.h中没有声明返回值,C语言中默认返回值为int型,这样又不一致了。应该把searchDlg.h中的定义修改如下:
    void Search_Directory(char* szFilename);
    

    

此问题由李海回答。

附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, 错误信息, error, error message, link, compile, runtime

   
 
把这个问题推荐给朋友
   
 
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio