未定义的引用C++结构变量CoA
始终显示对结构COA数组的未定义引用 当我试图在其他函数中编写COA时,它总是显示错误未定义的引用C++结构变量CoA,c++,struct,C++,Struct,始终显示对结构COA数组的未定义引用 当我试图在其他函数中编写COA时,它总是显示错误 #include <iostream> #include <fstream> using namespace std; void printDiamondlattice() ; int N; // creating struct to store struct format{ public: string M; float x; float y; float z; }; int
#include <iostream>
#include <fstream>
using namespace std;
void printDiamondlattice() ;
int N;
// creating struct to store
struct format{
public:
string M;
float x;
float y;
float z;
};
int S;
int main()
{
cin >> S;
format* COA = new format[S] ; //Allocating Dynamic Arrays to store the coordinate for later use
do {
cin >> choice ;
} while( choice < 1 || choice > 4);
/////////////////////////////////////////////////
ofstream myfile;
printDiamondlattice();
myfile.close();
cout << N << endl;
}
这是使用struct COA数组的函数
void printDiamondlattice(){
float q = 0.25 ;
float p = 0.75 ;
ofstream myfile;
extern format COA[];
myfile.open ("Diamond.txt",ios::app);
for ( float i =0; i <= Lx ; i++) {
//to prevent there is some coordinate larger than the size entered
if ( i+q < Lx && j+q<Ly && k+q <Lz ){
myfile << "S " << i+q << " " << j+q << " " << k+q << endl;
COA[N] = {"C",i+q,j+q,k+q}; //this is where the error happened
N++;}
}}
我正在GNU GCC编译器中使用代码块13.12。该项目属于Console应用程序类型
我曾尝试更改format::COA[N]之类的内容,但它不起作用COA是在main中定义的,不能像这样引用。相反,您应该传递参数。请注意,您需要大小,以便进行边界检查!。请把凹痕修好