简体   繁体   English

将Queues用作全局变量并从main处理其内容

[英]Using Queues as global and working on its contents from main

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 我收到有关模板参数无效的错误,也没有看到我将队列变量声明为全局..,我试图将它们放入函数中(但这不是我想要的,因为我想从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;
}

Your while statements are attempting to check the function std::queue::empty() itself, and not the result of a call to the function. 您的while语句试图检查函数std :: queue :: empty()本身,而不是函数调用的结果。 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. 正如overcoder的评论所说,添加括号将修复代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM