我一直在編程一個代碼來模擬一些傳導傳輸問題,但我被困在了網格的生成中。這是因爲我可能會使用變量的聲明錯了... MAIN:外部變量聲明不能在C++中工作(使用頭文件崩潰)
#include <iostream>
#include <fstream>
#include <string>
#include "library.h"
using namespace std;
int main (void){
// Number of divisions
int xdivA, xdivB, ydivA, ydivB, ydivAB;
xdivA=30; xdivB=30; ydivA=30; ydivB=30; ydivAB=30;
int N=xdivA+xdivB;
int M=ydivA+ydivB+ydivAB;
struct controlvolume celln[N][M];
}
頭文件
//GLOBAL VARIABLES
extern int N;
extern int M;
//STRUCTURE TYPES
struct prop {
double rho, Cp, k;
};
struct points {
double x, y;
};
struct controlvolume {
points coord;
prop localmaterial;
};
// FUNCTIONS
double Mesh(controlvolume celln[N][M], int xdivA, int xdivB, int ydivA, int ydivB, int ydivAB, points initialp[4], prop materials [4]);
Mesh.cpp使用
#include <iostream>
#include "library.h"
using namespace std;
double Mesh(controlvolume celln[N][M], int xdivA, int xdivB, int ydivA, int ydivB, int ydivAB, points initialp[4], prop materials[4]){
celln[2][2].coord.x=initialp[3].x;
celln[2][2].localmaterial.rho=materials[2].rho;
}
所有的變量如mainp,材質等在主函數中聲明。我沒有把它們包括在這裏以節省空間。
即我正的錯誤是:
[錯誤]數組邊界不是一個整數之前常數「]」令牌
[錯誤]數組邊界不是一個整數之前常數「]」令牌
[錯誤]之前預期 ')' '' 令牌
[錯誤] 'INT' 之前預期不合格-ID
這似乎是在升ibrary.h文件,當定義函數Mesh時...
我很感謝你的幫助! :)