簡體   English   中英

為什么我在 header 文件“'vector'之前的預期初始化程序”中收到此錯誤

[英]Why am I getting this error in header file “expected initializer before 'vector'”

編譯項目時出現此錯誤:

g++ -I./src -MMD -MP -std=c++11 -c -o src/scape.o src/scape.cpp

scape.cpp 中包含的文件之一是 tools.hpp,我在此文件中收到錯誤消息:

src/tools.hpp:4:2: 錯誤: 'vector' 之前的預期初始化程序

下面是 tools.hpp 代碼:

#ifndef TOOLSHPP
    #define TOOLSHPP

    vector<int> decToBinary (unsigned long long int , int );
    int countFreq (string , string);
    vector<string> split_string (string ); 
    void remove_if_in_list (vector<int>& , vector<int> );
    vector<int> union_of_vectors (vector<int>, vector<int>); 
    void remove_file (string );
    void call_delay();

#endif 

所以我期待這個錯誤是由於我在“向量”之前缺少的東西,但我真的不明白它是什么?

已編輯

在嘗試了一些想法之后,我還發現錯誤不僅與“向量”有關。 如果我更改上述代碼中的行導致以下代碼,則錯誤將更改為:

src/tools.hpp:7:2:錯誤:“int”之前的預期初始化程序

#ifndef TOOLSHPP
    #define TOOLSHPP

    #include <string>
    #include <vector>

    int countFreq (std::string, std::string);
    std::vector<int> decToBinary (unsigned long long int, int);
    std::vector<std::string> split_string (std::string); 
    void remove_if_in_list (std::vector<int>&, std::vector<int>);
    std::vector<int> union_of_vectors (std::vector<int>, std::vector<int>); 
    void remove_file (std::string);
    void call_delay();

#endif

謝謝您的幫助。

錯誤實際上在另一個文件“pos_processing.hpp”中(如下):

#ifndef POSPROCESSINGHPP
    #define POSPROCESSINGHPP

    #include "types.hpp"

    void update_report (MyGraphType, vector<int> , int , int , map<int,vector<errorProbabilityType>>& );
    void generate_report (string , string , map< int, vector<errorProbabilityType> > )

#endif

最后一個 function 聲明中缺少分號。 此 header 文件與其他頭文件一起包含,如下所示。

#include "scape.hpp"
#include "exprtk.hpp"
#include "types.hpp"
#include "debug.hpp"
#include "pre_processing.hpp"
#include "pos_processing.hpp"
#include "tools.hpp"
#include "scape_utils.hpp"

由於錯誤是文件最后一行中缺少分號,編譯器理解下一行(在下一個包含文件中)是前一行的一部分,並最終在下一行中指示錯誤,即位於“tools.hpp”文件中。 這就是為什么錯誤在一個文件中但在另一個文件中顯示的原因。

您的tools.hpp文件似乎沒有使用#include <vector>std命名空間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM