包含的类类型显然没有声明,为什么?

Included Class Type is apparently not declared, why?

本文关键字:声明 为什么 类型 包含      更新时间:2023-10-16

编译器抛出了以下问题:

include/FlowChannel.h:14:21:错误:"LatticeCell"未在此范围内声明 标准::矢量网格;

当有这 3 个头文件(LatticeCell.hFlowChannel.hUtilities.h(和 2 个包含它们的 cpp 文件(lbm.cppUtilities.cpp(:

LatticeCell.h

#ifndef LATTICECELL_H
#define LATTICECELL_H
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
/* Single cell */
using namespace std;
class LatticeCell{
private: 
std::vector<double> matrix = {0,0,0,0,0,0,0,0,0}; 
unsigned int type;   //fluid, no-slip, velocity or density 
public: 

//Constructor
LatticeCell(unsigned int inType){
type = inType; 
}
};
#endif

FlowChannel.h

#ifndef FLOWCHANNEL_H
#define FLOWCHANNEL_H
#include <vector>
#include <string>
#include <cmath>
#include <iostream>
#include "LatticeCell.h"
using namespace std;
class FlowChannel{
private: 
std::vector<LatticeCell> grid;            //ERROR LINE
unsigned int dimX = -1; 
unsigned int dimY = -1; 
public: 
FlowChannel(unsigned int nx, unsigned int ny){
dimX = nx+2;
dimY = ny+2;
unsigned int gridSize = dimX*dimY; 
grid.reserve(gridSize);
initGrid(/*TODO Params*/); 
}
};
#endif

lbm.cpp

#include <string>
#include <vector>
#include "LatticeCell.h"
#include "FlowChannel.h"
#include "Utilities.h"
int main(int argc, char** argv){
printsomething();
return 0; 
}

Utilities.cpp

#include "LatticeCell.h"
#include "FlowChannel.h"

#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
void printsomething(){
cout << "something" << std::endl; 
}
double calcRelaxationTime(unsigned int ny , double reynolds, double uin){
return 3.0 * (uin * ny / reynolds) - 0.5;
}

Utilities.h

#ifndef UTILITIES_H
#define UTILITIES_H

#include "LatticeCell.h"
#include "FlowChannel.h"
#include <vector>
#include <cmath>
void printsomething(); 
#endif

此外,我的编译器标志是:

-Wall -std=c++17 -pedantic 

出于某种原因,我无法弄清楚,为什么LatticeCell不会成为FlowChannel中声明的类,因为它被包括在内。你们知道怎么了吗?

编辑:我添加了lbm.cppUtilities.cppUtilities.h,所以你们看到了问题的全部范围

您应该检查文件是否在同一目录中。 我在VS 2019中复制并粘贴您的代码,它对我有用, 这是图片 流道晶格单元

似乎,删除#include 'LatticeCell.h'FlowChannel.h之外的任何地方。老实说,我没有 100% 收到错误,因为这不会立即导致会导致此类错误的包含循环,但它有效。