使用全局队列并从 main 处理其内容

发布于 2024-12-07 13:42:12 字数 1861 浏览 0 评论 0原文

我收到有关模板参数无效的错误,并且没有看到我将队列变量声明为全局变量..,我尝试将它们放入函数中(但这不是我想要的,因为我想从 main 进行双端队列)并且也不起作用..这是我的错误和代码

program.cpp: In function ‘int main(int, char**)’:
program.cpp:62:24: error: argument of type ‘bool (std::queue<std::basic_string<char> >::)()const’ does not match ‘bool’
program.cpp:62:24: error: in argument to unary !
program.cpp:68:23: error: argument of type ‘bool (std::queue<std::basic_string<char> >::)()const’ does not match ‘bool’
program.cpp:68:23: error: in argument to unary !






#define _XOPEN_SOURCE 500
#include <ftw.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <iostream>

#define SIZE 100

using namespace std;

  queue<string> bfFilesQueue;
  queue<string> bfDirsQueue;

static int display_info(const char *fpath, const struct stat *sb,
             int tflag, struct FTW *ftwbuf)
{

    //Check the type of Flag (i.e File or Directory)
    switch(tflag)
    {
        case FTW_D: 
        case FTW_F: 
                    bfFilesQueue.push(fpath);
                    break;

        case FTW_DP: 
                     bfDirsQueue.push(fpath);
                     break;
    }
    return 0; /* Continue */
}

int main(int argc, char *argv[])
{

    if (argc != 2) {
        fprintf(stderr, "Usage: %s directory_name\n", argv[0]);
        return 1; 
    }  

    int flags = FTW_DEPTH | FTW_MOUNT | FTW_PHYS;


    if (nftw(argv[1], display_info, 20, 1) == -1)
    {
        perror("nftw");
        return 255;
    }
   printf("***************************\n");

   while(!bfFilesQueue.empty)
   {
       cout << bfFilesQueue.front() << " ";
        bfFilesQueue.pop();
   }

   while(!bfDirsQueue.empty)
   {
       cout << bfDirsQueue.front() << " ";
        bfDirsQueue.pop();
   }


    return 0;
}

I am getting errors about the template arguments not being valid and it is not seeing that I declared my queue variables as global.., i tried putting them inside the function (but thats not what I want because i want to deque from main) and does not work either.. Here are my errors and code

program.cpp: In function ‘int main(int, char**)’:
program.cpp:62:24: error: argument of type ‘bool (std::queue<std::basic_string<char> >::)()const’ does not match ‘bool’
program.cpp:62:24: error: in argument to unary !
program.cpp:68:23: error: argument of type ‘bool (std::queue<std::basic_string<char> >::)()const’ does not match ‘bool’
program.cpp:68:23: error: in argument to unary !






#define _XOPEN_SOURCE 500
#include <ftw.h>
#include <stdio.h>
#include <string>
#include <queue>
#include <iostream>

#define SIZE 100

using namespace std;

  queue<string> bfFilesQueue;
  queue<string> bfDirsQueue;

static int display_info(const char *fpath, const struct stat *sb,
             int tflag, struct FTW *ftwbuf)
{

    //Check the type of Flag (i.e File or Directory)
    switch(tflag)
    {
        case FTW_D: 
        case FTW_F: 
                    bfFilesQueue.push(fpath);
                    break;

        case FTW_DP: 
                     bfDirsQueue.push(fpath);
                     break;
    }
    return 0; /* Continue */
}

int main(int argc, char *argv[])
{

    if (argc != 2) {
        fprintf(stderr, "Usage: %s directory_name\n", argv[0]);
        return 1; 
    }  

    int flags = FTW_DEPTH | FTW_MOUNT | FTW_PHYS;


    if (nftw(argv[1], display_info, 20, 1) == -1)
    {
        perror("nftw");
        return 255;
    }
   printf("***************************\n");

   while(!bfFilesQueue.empty)
   {
       cout << bfFilesQueue.front() << " ";
        bfFilesQueue.pop();
   }

   while(!bfDirsQueue.empty)
   {
       cout << bfDirsQueue.front() << " ";
        bfDirsQueue.pop();
   }


    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半仙 2024-12-14 13:42:12

您的 while 语句试图检查函数 std::queue::empty() 本身,而不是调用该函数的结果。错误消息中显示的类型是函数的类型。

正如 overcoder 的评论所说,添加括号将修复代码。

Your while statements are attempting to check the function std::queue::empty() itself, and not the result of a call to the function. The type that appears in your error message is the type of the function.

As overcoder's comment says, adding parentheses will fix the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文