0
我得到錯誤的模板參數無效,它沒有看到我宣佈我的隊列變量爲全球..我試圖把它們放入函數(但那不是我想要的,因爲我想從主到雙端隊列),並沒有工作,要麼。這裏是我的錯誤,代碼使用隊列作爲全局和工作在其主要內容
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;
}
bfFilesQueue.empty()而不是bfFilesQueue.empty。你在調用一個方法。 bfDirsQueue也一樣。 – overcoder
我剛剛恢復編輯。不要只是編輯你的問題,即使它已經解決了。這隻會讓後來來到這個網站的其他人感到困惑,並且不知道問題是什麼。 –