undefined reference C ++ struct variable COA

时间:2014-10-03 14:51:58

标签: 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 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的ARRAY

的功能
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。该项目属于&#34;控制台应用程序&#34;

我试图更改格式:: COA [N]之类的东西,但它不起作用

0 个答案:

没有答案