我想爲我的研究實現一個有限元代碼。我需要創建一張地圖,將材料與他們的名字相關聯,以便我可以通過名稱訪問它們。 從主類的頭文件,我定義如下:爲剛剛聲明的類定義一個stl容器。
/// Friend class definition for the materials
friend class Material;
/// Class definition for the materials
class Material;
/// Creates a dictionary of elementsets vs material names
std::map<std::string,std::string> _material_assignment;
/// Container to hold the material names of all the materials
std::map<std::string,Material> _materials;
主類的實現編譯。但是,當生成文件到達主文件時,出現以下錯誤:
Error: 'std::pair<_T1, _T2>::second' has incomplete type
_T2 second; /// @c second is a copy of the second object
^
In file included from src/main.C:5:0:
src/diff_code.h:228:9: error: forward declaration of 'class DiffCode::Material'
class Material;
如何解決此問題。我的代碼中所有包含重要代碼類的頭文件的其他文件都正在編譯中。
謝謝!
什麼阻止您包含'Material'類的定義而不是僅包含前向聲明? – Praetorian