2013-11-20 111 views
0

我有以下的結構,主要宣佈(沒關係成員!):結構作爲構造函數的參數(在主申報)

struct args 
{ 
    std::vector<string> names; 
    std::vector<std::shared_ptr<RegularExpression>>vreg; 
    std::vector<string> stopFile; 
    std::vector<string> groundTruth; 
    int debug; 
}; 

,我有一個CLASSE驗證這需要ARGS作爲構造函數的參數

#ifndef VERIFICATION_H 
#define VERIFICATION_H 

class Verification 
{ 
    public: 
     Verification(std::string, std::vector<double>,double,args); 
    private: 
     args _A; 

} 
#endif // VERIFICATION_H 

現在主:

struct args 
    { 
     std::vector<string> names; 
     std::vector<std::shared_ptr<RegularExpression>>vreg; 
     std::vector<string> stopFile; 
     std::vector<string> groundTruth; 
     int debug; 
    }; 
    int main() 
    { 
     Verification v("res.cr",gt, 0.75,A); 
     return 0; 
    } 

我有以下的編譯錯誤:

  1. Verification.h | 33 |錯誤: 'ARGS' 沒有指定類型| (這個錯誤是針對班級_A中的私人成員的)
  2. main.cpp | 153 |錯誤:沒有匹配函數調用'Verification :: Verification(const char [7],std :: vector &,雙,參數&)'|
  3. Verification.h | 24 |錯誤:'args'尚未聲明| (此錯誤是構造函數)

如何使用主聲明爲驗證類構造函數的參數結構?

謝謝。

+1

偏離主題,但不應該像'_A'那樣使用[保留名稱](http://stackoverflow.com/questions/228783)。 –

+0

噢,是嗎?而愚蠢的我,我認爲我做了正確的事情大聲笑。我有一個法國公司的概述,在他們的代碼中,他們做的和我一樣。 我甚至問他們爲什麼你沒有構造函數和複製構造函數,這是C++中的經驗法則。 她回答說:NAAAAAAAAAAAAAA我們不需要它。殺死我 –

回答

2

該結構必須以Verification類翻譯單元可見的方式定義。我建議你將結構移動到它自己的頭文件中,並#include在你的主文件和Verification.h中。

+0

啊,這聽起來不錯。 –

2

第一個錯誤是編譯class Verification時編譯器必須先看到struct args第一個。它不知道你是後來gigig定義struct args

簡單的修復方法是將struct args的定義移動到Verification.h

修復這個問題,你仍然會有其他錯誤(最明顯的是A沒有定義),但是當你接近它們時我們可以處理這些錯誤。

1

你的第二個錯誤是由於字符串文字是const char[]而不是std::string - 你需要創建一個string,然後再將它傳遞給一個期望字符串的函數。

此外,gtA需要在此調用之前定義。

+0

第一個參數ok綠巨人。我糾正了它 –