使用全局队列并从 main 处理其内容
我收到有关模板参数无效的错误,并且没有看到我将队列变量声明为全局变量..,我尝试将它们放入函数中(但这不是我想要的,因为我想从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 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.