现在我已经遇到了这个问题,但不会忘记包含一些标题或定义,但它不是警告的错误。
我的files.h
;
class Files
{
public:
explicit Files(const char *p_path = 0);
~Files();
/* .... */
private:
std::string path;
}
我的files.cpp
;
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h> // I added this line with @Kerrek SB's advice but nothing changed
#include <dirent.h>
#include <files.h>
static DIR *p_dir = NULL;
static struct dirent *p_ent = NULL;
Files::Files(const char *p_path)
{
if (p_path == NULL)
{
std::cerr << "PATH is NULL" << std::endl;
exit(EXIT_FAILURE);
}
path = p_path;
p_dir = opendir(p_path);
if (p_dir == NULL)
{
std::cerr << "Cannot open " << path << std::endl;
exit(EXIT_FAILURE);
}
}
Files::~Files()
{
if (p_dir)
{
/* Here is my warning occuring in this line and the definition
line p_dir 'static DIR *p_dir = NULL' */
delete p_dir; // After changing this line with 'free(p_dir);' warnings gone.
p_dir = NULL;
}
}
定义行 ( static DIR *p_dir = NULL;
) 处'p_dir' has incomplete type
的警告是,删除行 ( delete p_dir;
) 处的警告是possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
。
更改delete p_dir;
with后free(p_dir);
,两个警告都消失了。我不知道它的确切原因,但它听起来像DIR *
type 的行为void *
。我只是在胡乱猜测。
希望这可以帮助。