English 中文(简体)
DIR类不完整的使用无效
原标题:Invalid use of incomplete type DIR

I m 试图汇编该代码,该编码在Windows上操作,在LC(Code:Blocks):

/* Edit: Includes */
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <...>
/**/

/* === */

/* Function code */
DIR *dp;
dirent *ep;
string name_parent;

dp = opendir(somepath);
name_parent = dp->dd_name; //error
/**/

由于Windows上的道路名称不敏感,我可以读到用户的投入,如“c://programfile”和“校正”途径“C:Programfiles*”(星号除外——或“F://”->“F:*”)。 我也利用这一变量获得一张含有绝对道路价值的目录,因为(在部分读者(当然)之后)回归了一条与某些小段相对的道路。

On Linux, I get a compiler error (for "dp->dd_name"):

差错:DIR类不完整的使用无效

Did I forget something? Or is there a logical error?

www.un.org/spanish/ga/president

问题回答
/* Edit: Includes */
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <...>
/**/

/* === */

/* Function code */
DIR *dp;
dirent *ep;
string name_parent;

dp = opendir(somepath);
ep = readdir(dp);
name_parent = ep->d_name;

/**/

变数d - 名称存在于显示名录名称的建筑群中

You didn t declare the type of DIR! On Posix systems, you would have said,

#include <sys/types.h>
#include <dirent.h>

然而,在Windows,你没有这些特征。 相反,你可以使用。 视窗软件系统功能

是的,你遗漏了头版档案。

dirent.h

<代码>DIR的内部结构没有说明,因此,你永远不应依赖该编码,并期望你的代码能够携带。

Windows的校准来源就这样说:。 DIR:

/*
 * This is an internal data structure. Good programmers will not use it
 * except as an argument to one of the functions below.

很显然,在你试图使用时,没有界定“<代码>DIR的类型。 您是否可选择<条码>。

在我面临这一问题时,不要忘记包括一些头脑或定义,而不要错误地把它当作警告。

缩略语

class Files
{
public:
    explicit Files(const char *p_path = 0);
    ~Files();

    /* ....  */
private:
    std::string path;
}

缩略语

#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 = NUL;)为 p_dir'不完整的,删除线上的警告(ete p_dir;)为在雇用删除操作者时发现的可变问题: [-Wdelete-incomplete]

After changing the delete p_dir; with free(p_dir); the both warnings are gone. I don t know it s exact reason but it sounds like DIR * type acting like void *. I m just taking a wild guess.

希望这一帮助。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签